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.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.