A question about arrays and parameters. Why doesnt this work?

At startup, I created the following array:

*create_array sample_spell 3 false false false

At intro I call:

*gosub_scene spell_system learn_spell “sample_spell”

And at spell_system.txt I have:

*label learn_spell
*params spell_name
*set {spell_name}[1] true
*set {spell_name}[2] false
*set {spell_name}[3] true

*return

However this code doesn’t work. CSIde says the following error: “line 11 of spell_system: Non-existent variable ‘sample_spell’”. Why is that? @_@

The Variable DOES exist. This would work if it wasn’t an array. What am I misunderstanding?

1 Like

Have you tried this without the curly braces around the variable name? Those seem unnecessary…

Sadly it doesn’t fix if I remove the curly braces, it stops using the parameter and then the error is: Non-existent variable ‘spell_name_1’.

1 Like

Oh well, apologies. I thought it was generally about arrays… Let’s wait for an expert (I am a bit curious about this now lol).

1 Like

Try this:

*set { spell_name & "_1" } true 

In ChoiceScript, array notation is just syntax sugar. Behind the curtain, CS creates as many simple variables and just appends a suffix. You can access them by name (in this case sample_spell_1) or by array notation (sample_spell[1]). There are no real arrays in ChoiceScript.

When you use a variable by reference, it’s going to resolve the reference part of the command first. That’s why *set {spell_name}[1] true is not going to work.

3 Likes

OMG IT WORKS

Thank you thank you thank you!

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.