variable changes in twine

is there any to change the value of a variable in twine without needing to add a whole passage for the interaction?

You don’t need a whole passage. Which version are you using so we can give the exact syntax?

In he general case, yes, but also no.

Any random bit of JavaScript can alter a Twine variable. That’s the yes bit.

In general the state of variables are only looked at when a new passage is chosen and the displayed page’s HTML is updated. What you see is a snapshot of the variables state at render time. Some story formats have work arounds for this (or you can re-write the page directly). You need to tell people which format you are using.

I’m not sure exactly what you’re asking. Are you wanting a button to change variables or like running a function etc

All would have to be called in a passage sorta, but you could modify variables in JavaScript


“State.variables.yourvariable += xyz”

Or in a link like

”<<link [[linkname|passagename]]>><<set yourvariable to xyz>><</link>>”

Or a widget
“<<widget “widget name”>><<set yourvariable to xyz>><</widget>>”

But I think your widgets or functions would have to be called in a passage or in the story’s caption etc
I think you can also use timers or setup listeners, but twine primarily works around the rendering of passages and what not
As far as I know. I’m still rather novice with it

I’m new to twine (I’m using twine 2 btw) as in I literally started using it a few days ago but yeah I meant like just pressing a button to change a variable rather than having a link to a new passage with the variable change

Ah! Okay. In that case you can do either of these

<<button “buttonsname”>>things you want the button to do<</button>>


<<link “linkname”>>things you want the link to do<</link>>

In the case of the link you can model it to send to the same passage you’re on if you want to refresh the contents and such. Like

<<link [[linkname|linkedpassage]]>>stuff you want it to do<</link>>

Also for reference this might not be correct for base twine 2

I’m using twine 2 with the sugarcube plugin