Previous Variable Code

Twine Version: Sugarcube 2.36.1

So recently I came back to coding again on Twinery Sugarcube with a new Idea.
But immediately stumped with a piece of code I want to add.

I want to make a Code that will check the previous Number/Name of a Variable.

For Example:
<<if $previousLocation eq = 1>> This text will play <<elseif $previousLocation eq 2>> This text will Play. <</if>>
Can someone explain how to do this or possibly point me in a Direction to help

I am not sure you can check the previous value of a variable (and if it is, it’s probably not wise do to so).

If you explain to us what exactly you are trying to check (ex: the player went through a certain passage or did a certain action), it would make it easier to help :slight_smile:

If it is just checking the previous passage (from the name of the variable:
<<if previous() is "PassagaName">> should do the trick.

I dont know of an automated way but seems simple enough a manual process. If I were to change a variable, first thing to do is save it

For the record, it is possible, with State.index(), as long as that moment is still in the history. For example, State.index(State.length - 1) will give you the value of $foo in the previous moment.

That said, yeah, there is almost certainly a better way to do what OP wants, whether it’s using previous() or storing the old value in a separate variable. You should never actually do this.

1 Like

Thank you Svlin and Manon

1 Like