It looks like you're new here. If you want to get involved, click one of these buttons!
StoryInit <<set $LOW_SKILL = 1>> <<set $MID_SKILL = 2>> <<set $HIGH_SKILL = 3>> <<set $SALARY[$LOW_SKILL] = 100>> <<set $SALARY[$MID_SKILL] = 200>> <<set $SALARY[$HIGH_SKILL] = 300>> Somewhere in passages: <<set $skill = $LOW_SKILL>> (or $MID_SKILL or $HIGH_SKILL) <<set $money += $SALARY[$skill]>>I have error: <<set>> bad evaluation. Cannot set property "1" of undefined.
Comments
You need to declare that Javascript Array before you can use it, and unless you add all it's elements at the time of declaration you will also need to the push() method to add new elements. You can access (and change) any existing element of the array using the syntax in your example.
WARNINGS:
a. Array index's are zero base, so the first element is 0 not 1.
b. Story variable don't automatically default to zero, so you need to assign zero to a variable before adding a number to it's current value.
eg. Creating an $salary array with two elements, then adding a third element and changing the current value of the second element. NOTE: I used upper case variable names for those who's value is consistent, and changed the other to mixed case with the first letter being lower case. eg. $someLongName.
Note that arrays are 0 based, so setting your first value to index 1 means that certain methods may work oddly.
Additionally. Arrays are 0-based, not 1-based. Meaning, unless you're using it for something not shown in your example, you're wasting the first element in the array by defining $LOW_SKILL as 1 instead of 0.
$SALARY to [] - exactly what I need. Maybe it's good example of usege for this page http://www.motoslave.net/sugarcube/2/docs/markup.html#naked-variables