Does ChoiceScript do arrays?

I’ve read the documentation but couldn’t find any reference to them.

I want to have an array so that I can have a map–for example $map[2][3] would store whatever is due south of $map[2][4].

2 Likes

Yes.

Creation:

*create array_1_1 "Tim"
*create array_1_2 20
*create array_1_3 "tall"

*create variable_number 3

Usage:

${array[1][1]} is ${array[1][2]} years old and he is ${array[1][variable_number]}.

Result:

Tim is 20 years old and he is tall.

In CS, arrays start at 1.

4 Likes

Thanks!

Where is the page that deals with this? I missed it completely.

How would I assign a value to, for example, $array[$x][$y]?

There ain’t any on the wiki.

What exactly do you mean with the $s ?

You can use *set in the same way as I used the *create.

1 Like

Array has never been a fully developed feature. This is probably the best article on its doc.

4 Likes

What exactly do you mean with the $s ?

My mistake.

You can use *set in the same way as I used the *create.

So, for example, this would work:

*set map_x_y z

?

Array has never been a fully developed feature. This is probably the best article on its doc.

Thanks. Is there a master document which collects all these articles? If not, how do I find what features the language has and doesn’t have?

Yes. The only way to make arrays is using the create, you can’t dynamically size them like other languages (such as using push in JS and such).

If its not on the wiki best place to find them is from those announcements.

2 Likes

could some kind person explain what i might use arrays for in choicescript? or point me to something that would explain their usefulness. tia

Here is an example of an use:

2 Likes

could some kind person explain what i might use arrays for in choicescript?

Broadly, if you have a large number of variables, and there’s a particular operation that could be applied to any of them.

For example, you might have a character with attributes like Strength, Intelligence etc.

When you’re generating this character, each of these attributes might start as a random number from 1-100.

You could have each one as a separate variable, and generate each one individually.

But it would be easier, and more usual, to have an array, named for example ‘attributes’, with Strength being attributes[1], Intelligence being attributes[2] and so on.

Then you could write a for…next loop, with the command to set the zth slot of attributes to a random number between 1 and 100.

At another point in the game there might be a branching point where you lose an amount from a random attribute. Again, you could do this by generating a random number, and then if z is 1 take something from Strength, if it’s 2 take something from Intelligence and so on. But it would be easier to have a single line saying take something from the zth slot of attributes.

1 Like