0 votes
by (220 points)
Hi all, I'm odviously new to twine and have been searching high and low for answers to this, but how can I get this to work properly?

Skill Points: $skp

Strength: $str

[[Add|Skill Point Distribution][$skp -= 1]|[$str += 1]]

[[Subtract|Skill Point Distribution][$skp += 1]|[$str -= 1]]

2 Answers

0 votes
by (159k points)

Place a comma between each of the individual assignments within your Link with Setter mark-up based links.

[[Add|Skill Point Distribution][$skp -= 1, $str += 1]]

[[Subtract|Skill Point Distribution][$skp += 1, $str -= 1]]


note: If you are trying to implement a number pool based skill assignment system then you should checkout the <<numberpool>> macro addon found in the Add-ons section of the main page of the SugarCube 2 web-site, as it is specifically designed for that task.

0 votes
by (44.7k points)

To make your above code work, you'd want to change it like this:

Skill Points: $skp

Strength: $str

[[Add|Skill Point Distribution][$skp -= 1, $str += 1]]

[[Subtract|Skill Point Distribution][$skp += 1, $str -= 1]]

You can use a comma to separate different values being set.

That said, rather than reloading the passage, you might want to do this instead:

<span id="stats">
Skill Points: $skp

Strength: $str
</span>
<<button "Add">>
	<<set $skp -= 1>>
	<<set $str += 1>>
	<<replace "#stats">>
		Skill Points: $skp
		
		Strength: $str
	<</replace>>
<</button>>

<<button "Subtract">>
	<<set $skp += 1>>
	<<set $str -= 1>>
	<<replace "#stats">>
		Skill Points: $skp
		
		Strength: $str
	<</replace>>
<</button>>

Doing it that way would let the button clicks immediately update the display of values.

If you're going to have a lot of buttons like this, you may want to shorten things like this.  First, make a passage named "Stats" which just shows the stats like this:

Skill Points: $skp

Strength: $str

Then the above code could be shortened like this:

<span id="stats"><<include "Stats">></span>
<<button "Add">>
	<<set $skp -= 1>>
	<<set $str += 1>>
	<<replace "#stats">><<include "Stats">><</replace>>
<</button>>

<<button "Subtract">>
	<<set $skp += 1>>
	<<set $str -= 1>>
	<<replace "#stats">><<include "Stats">><</replace>>
<</button>>

One thing to note, if the player changes values and then saves before another passage transition, the changes won't be saved.  The save system normally only saves the values that variables had just before the player entered the passage.  If they save after loading a passage (either a different passage or the same one), then the changes will save just fine.

Hope that helps!  :-)

...