Arrays in Generic Objects Sugarcube 2.33.2

Twine Version: 2.35
Story Format: Sugarcube 2.33.2

Hey - I’m trying to keep my global variables relatively organised by grouping them in generic objects. I have a problem when the variables are themselves arrays.

<<set $supermarket={}>>
<<set $supermarket.pronounsIndex=0>>
<<set $["It is", "You are"]>>
<span class="It">It is</span> 
in the supermarket.
<<repeat 4s>>
<<if ++$supermarket.pronounsIndex>1>><<set $supermarket.pronounsIndex=0>><</if>>
<<replace ".It">><<timed 0s t8n>>$[$supermarket.pronounsIndex] <</timed>><</replace>>

this produces alternately:

It is, You are[1]
in the supermarket.


It is, You are[0]
in the supermarket.

so $ outputs the contents of the whole array and [$supermarket.pronounsIndex] outputs the value of pronounsIndex inside square brackets. Is there a way to get the array value out like if i was working with standard arrays or do I have to abandon the $supermarket holder object?


Does it work if you wrap it in <<print >>? Like:

<<print $[$supermarket.pronounsIndex]>>
1 Like

Yeah, SugarCube’s naked variable syntax only supports a limited number of forms, and that’s not one of them, so you’ll have to use <<print>> or <<=>> as @tayruh suggests.

Edit: (you can do a .property or a [index] but not both)

1 Like

Doh! That’s it. Thank you!