Can custom variable declaration somehow be made possible?

Can somebody make an extrention or integrate this function in MakeCode?

This way it is possible to make multiple variables mid-game and allow finally displaying an unlimited number of saved settings (settings already can be done this way, so why not functions?)

1 Like

Hmm… Not quite what I asked for

1 Like

What you’re describing here effectively comes down to either an array or an object (https://github.com/microsoft/arcade-block-objects). The variables map to ‘normal’ javascript variables, which are all defined at declaration – it is uncommon to have dynamic variable names in programming languages as arrays / objects / maps cover that use case more accurately.

The case you mentioned (set variable0, set variable1, set variable2) is an example of when you would use an array – you create one and then index into it to grab values.

For arbitrary / non integer values, you would use objects to store groups of values - you keep around one variable and store things on top of that. (It’s possibly worth noting this is significantly slower, in particular on hardware, than using arrays and normal variables - something on the order of like 10-100 times longer to access the variable).

2 Likes

Yeah, but what if I need to show many text sprites at once? Then this happens:


Sure I can make a temporary variable that will store an array value and then repeat that but increase the index that it is collecting by one. However when I need to destroy said sprites it will only work once. That is kind of a bummer. Any way to avoid this?

You can make an array of text sprites instead :slight_smile:

also, instead of the repeat block, there are two other loop blocks that will more easily handle these; this one will do something once for each value in list:

image

as will this, except this gives you an index as well (like you were doing manually with ‘selector’)

image

2 Likes

Thanks!

1 Like