0 votes
by (2.7k points)

Here is the code that causes the glitch:

<<set $array1 = ["X","Y","Z"]>><<set $array2 = ["A", $array1]>>
<<print $array2>> -> returns: ["A",["X","Y","Z"]]
<<set $array1[1] = "N">>
<<print $array2>> -> still returns: ["A",["X","Y","Z"]]

How can I fix this so that array2 is updated wheneve array1 is?

1 Answer

+1 vote
by (320 points)
Are you sure it isn't working right? I pasted the code exactly as you have it, and it works just fine for me with SugarCube 2.21.0 and Twine 2.2.1.
by (8.6k points)
There's probably a passage transition in there somewhere OP failed to mention. Those break references in SugarCube.
And the workaround in this case would be: don't use them. Expect all state variables to be a deep clone after you transition passages and code with this knowledge.
...