Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sugarcube 2.x, making a variable to not get saved in each state, in between passage transitions

Hi all,

I would like to define variables such that they won't be get saved each time in States object, like a constant, because I have lots of javascript object that they dont change throughout my twine project but they are defined with $ prefix. My twine project started to have lags because of huge collection of objects that's (I suppose- ) cloned each time when I proceed to a new passage.

But they must be accessible globally, within the twine system like how I normally access a variable;
// in some mysterious passage

<<for each _item in constant_object_collection_somehow_global>>

<<print _item[_i].name>>

Comments

  • You want to store static variables that don't change during your game using a setup object.

    Put something like this into your JavaScript:
    setup.MyVariable = "This is my variable";
    

    The you can call it later using for example:
    <<print setup.MyVariable>>
    

  • edited June 2017
    idling wrote: »
    You want to store static variables that don't change during your game using a setup object.

    Put something like this into your JavaScript:
    setup.MyVariable = "This is my variable";
    

    The you can call it later using for example:
    <<print setup.MyVariable>>
    

    Mate that's tits! was exatcly was i was looking for! I tried to do sort of similiar thing, binding variable to a sugar object with
    State.test = 2
    
    but that gave me an error LOL. Thank you, also could you let me know where's this reference from? Because I 've read all documentation about sugar and twine, seems like I've missing some documentation?!

    (also how to mark this thread as ANSWERED?)
  • It's mentioned in the section for special variables.

    @greyelf talks about in in more detail here.
Sign In or Register to comment.