+1 vote
by (130 points)
In Sugarcube2, are all variables shared between all passages, or is there a specific thing that has to be done to create a "global" type variable visible to all passages?

1 Answer

+1 vote
by (63.1k points)

They're all shared, sort of. A story variable, e.g. $variable is copied to each new passage. This makes it possible to have a back button that can undo changes to variables. 

Temporary variables, like _variable are not copied over, and only exist until the next passage transition. 

If you want to create static variables, essentially constants that aren't copied to each new passage and therefore aren't part of the state, you can use the setup object. 


<<set $var to 3>>
/% $var will be copied to each new passage or moment %/

<<set _var to 3>>
/% _var will only exist in the current moment %/

<<set setup.var to 3>>
/% setup.var will be three even in past moments navigated to in the history %/

In answer to your question though, story variables are functionally global.