As a new developer for Choicescript it took ages to find documentation on arrays. I finally found this:
So I did lots of experimenting and found out some useful stuff (ancient software dveloper here, started in the 1970s.)
Part 1 is just what it tells you in the wikky, that square brackets append their content (with a leading underscore) onto the variable name to produce the final variable name for the script to work with.
So given:
*create fairy_1 “Beth”
*create fairy_2 “Slavos”
Then this code:
*temp fairy_id 2
${fairy[fairy_id]}
Will be interpreted as:
${fairy_2}
And the output will be:
Slavos
Ok, cool. The elements are static but there is a dynamic reference. So what about 2d arrays? I tried this:
*create fairy_1 “Beth”
*create fairy_2 “Slavos”
*create fairy_3 “Lissa”
*create fairy_type_1 “nice”
*create fairy_type_2 “naughty”
*create fairy_type_3 “nice”
*greeting_behavior_nice “Oh, so pleased to meet you.”
*greeting_behavior_naughty “Wadda you want?”
And I want the type of a fairy to tell me the behavior given a fairy ID. In other languages this could be handled by a 2D array of the form x[a][b]. But that is not how choicescript does things. It took a few experiments and I found this does the trick:
Fairy ${fairy[fairy_id]} sees you and says “{greeting_behavior[fairy_type[fairy_id]]}”
In other words, the structure is x[a[b]]
So with a fairy ID of 3, then
greeting_behavior[fairy_type[fairy_id]]
becomes greeting_behavior[fairy_type_3]
which becomes greeting_behavior_nice which results in:
Fairy Lissa sees you and says “Oh, so pleased to meet you.”
A 3d array would look like this x[a[b[c]]], and so on to whatever depth you need. I’m not sure how deep these substitutions can nest, but two was enough for my purposes.
If someone would like to verify this, and then update the wiki to include this it would be cool.
If someone is able to anoint me with wiki update powers I would be happy to do it myself once at least one other person has verified my work. I have a long history of good wikki gardening techniques.