Multiple Reactive Button Issues

Twine Version: Twine 2.6.0
Story Format: Sugarcube 2.36.1

I’m trying to use this code to distribute stat points to multiple different stats in one passage. But when I do so, Agility, Endurance and Mind don’t change when you click the buttons. It just shows the variable for the stat. Even when you change the order of that stats, only Brawn changes as you click the buttons. I tried setting the StoryInit passage stats to 5 when applicable, but that doesn’t change anything.

Also tried the Sugarcube 2 (2.18) “Player Statistics” Example, but that code has problems of it’s own. What exactly is wrong with this code and how can I fix it?

Stat Points: <<set $char.SP to 5>><span id="charSP">$char.SP</span>
Brawn: <<set $char.Brawn to 5>>\
<<button "-">>
	<<if $char.SP gt 0>>
		<<set $char.Brawn--, $char.SP++>>
		<<replace "#stats-Brw">>$char.Brawn<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>> \
<span id="stats-Brw">$char.Brawn</span> \
<<button "+">>
	<<if $char.Brawn lt 200 and $char.SP gt 0>>
		<<set $char.Brawn++, $char.SP-->>
		<<replace "#stats-Brw">>$char.Brawn<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>>

Agility: <<set $char.Agi to 5>>\
<<button "-">>
	<<if $char.Agi gte 6>>
		<<set $char.Agi--, $char.SP++>>
		<<replace "#statsAgil">>$char.Agi<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>> \
<span id="statsAgil">$char.Agi</span> \
<<button "+">>
	<<if $char.Agi lt 200 and $char.SP gt 0>>
		<<set $char.Agi++, $char.SP-->>
		<<replace "#statsAgil">>char.Agi<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>>

Endurence: <<set $char.End to 5>>\
<<button "-">>
	<<if $char.End gte 6>>
		<<set $char.End--, $char.SP++>>
		<<replace "#statsEndr">>$char.End<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>> \
<span id="statsEndr">$char.End</span> \
<<button "+">>
	<<if $char.End lt 200 and $char.SP gt 0>>
		<<set $char.End++, $char.SP-->>
		<<replace "#statsEndr">>char.End<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>>

Mind: <<set $char.Mind to 5>>\
<<button "-">>
	<<if $char.Mind gte 6>>
		<<set $char.Mind--, $char.SP++>>
		<<replace "#statsMnd">>$char.Mind<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>> \
<span id="statsMnd">$char.Mind</span> \
<<button "+">>
	<<if $char.Mind lt 200 and $char.SP gt 0>>
		<<set $char.Mind++, $char.SP-->>
		<<replace "#statsMnd">>char.Mind<</replace>>
		<<replace "#charSP">>$char.SP<</replace>>
	<</if>>
<</button>>

: :
StoryInit Passage
: :
<<set $char to {
name:" ",
Level:0,
Exp:0,
maxExp:0,
damagehp:0,
damagemp:0,
currHp:0,
maxHp:0,
currMp:0,
maxMp:0,
Brawn:0,
Agi:0,
End:0,
Mind:0,
PD:0,
MD:0,
MSP:0,
SP:0,
USP:0}>>

1 Like

The variable sigil is missing in three spots in your example, and as a result, after <<replace>> fires, the text is not updated with the value of your variable. Add $ in front of the variable names in these three places and it should work:

<<replace "#statsAgil">>char.Agi<</replace>>
<<replace "#statsEndr">>char.End<</replace>>
<<replace "#statsMnd">>char.Mind<</replace>>

Also, this probably isn’t intentional and you should fix it: when reducing Brawn, instead of checking if the stat is greater than 6 like with the other stats, you have <<if $char.SP gt 0>>. Which means that as long as unspent SP is greater than 0, you can always reduce Brawn, even going into negative values.

1 Like

Thanks! This helped a lot. I knew something was missing. My eyes just glazed over it.

1 Like