r/twinegames•
acmabrit

Can't figure out why buttons are not successfully changing variables [Twine 2, Sugarcube 2.36.1]

:SugarCube: SugarCube 2

So I'm creating a passage in Sugarcube 2.36.1 where the player must choose items from a semi randomly generated list. The intention was that there would be a number of buttons on the screen displaying different items, the buttons would disappear when the player click on them while adding the item to the player's inventory. I created a proof of concept where the buttons are displaying as intended and disappearing as intended, but not actually updating the inventory variables and I cannot figure out why.

The variables are set to 0 by a widget at game creation, so are pre-defined and I've also verified that they're not updating by adding a display of the variables to the side-bar.

Below is sample code from two of the buttons:


<span id="item1">

<<set $item1chance = random(1, 100)>>

<<if $item1chance lte 50>>

<<button "Canned Food">><<set $food += 1>><<set $pickedCount += 1>><<replace "#item1">>You grab canned food<</replace>><</button>>

<<else>>

<<button "Bottled Water">><<set $water += 1>><<set $pickedCount += 1>><<replace "#item1">>You grab bottled water<</replace>><</button>>

<</if>></span>

<span id="item2">

<<set $item2chance = random(1, 100)>>

<<if $item2chance lte 50>>

<<button "Canned Food">><<set $food += 1>><<set $pickedCount += 11>><<replace "#item2">>You grab canned food<</replace>><</button>>

<<else>>

<<button "Bottled Water">><<set $water+= 1>><<set $pickedCount += 1>><<replace "#item2">>You grab bottled water<</replace>><</button>>

<</if>></span>


Any help would be greatly appreciated.

Posted Jan 14, 2026, 3:02 AM UTC

13
Loading comments…