An array is used to group together related objects, so that you can refer to them by a number, rather than separate names.
For example, if you wanted to hold a list of birds, instead of having to think up as many variable names as there are birds (the amount of which you may not know when you are writing your program), you can have an array with a whole bunch of birds and refer to them by number (array index), including a number in another variable.
Instead of
*create first_bird “sparrow”
*create second_bird “robin”
*create third_bird “finch”
you could do
*create_array birds 3
*set birds[1] “sparrow”
*set birds[2] “robin”
*set birds[3] “finch”
It may seem in this example that arrays are pointless, but in more sophisticated programs they are very useful, especially when you use a variable for the index like
*input_text birds[current_bird]
Feel free to ask me any more questions or for clarification.
Well I may be a regular on this forum but I have no idea how actual code works. @amca would you mind ellaborating more on how an array is useful? Also it seems like it would be a lot of work to keep track of which bird is bird[1], bird[2], etc. Is it?
There are two main types of situation where you would use such an array.
The first situation is where you don’t care what order they are in, you just want them all grouped together so they are easier to manipulate.
The second situation is where the index (number) actually means something. For instance they could be in order of favourite bird. So the sparrow would be the favourite bird, the robin the second favourite bird and the finch the least favourite bird.
You can actually use looping code to declare *temp arrays, but for *create arrays, you’d have to define them manually. The reason one works, but the other doesn’t is due to the fact that all your *create lines must be in the same block of code, and this breaks when you try to do anything else.
Pretty sure I remember trying out loops with *temp. It’s been quite a while though, so I may either be mistaken, and I was just theorizing it could be done, or it’s been changed. I’ma have to test this out again either way.
Thanks for double checking for me. I hadnt gotten around to double checking it myself yet.
I’ve been going with programmatically generating the array initialisation code in Choicescript and then copy+pasting that code from the resulting web page into the text editor.
Honestly, as a programmer myself, I’ve been seriously considering writing a converting program to turn more program like code into CS coding. At the very least, I’ll probably write up a few helper programs to do things like initializing arrays, making copies of variables for checkpoints, repetitive if/elseif/else codes, etc…