0 votes
by (220 points)

I've been working on a passage where you get to boost the stats of your character three times before starting the game. I've been trying to use the replace: macro in the links for boosting the stats to show the updated values of the variables(stats) so I wouldn't have to refresh the passage every time I click the link in order to see the changes. Here's what I have so far:

(link-repeat: "Strength + 5")[{
	(set: $str to it + 5)
	(set: $statchoice to it - 1)
	(replace: ?str)[$str]
	(if: $statchoice is 0)[
		(goto: "CharacterDev5")
	]
}]

Problem is, it's not working. Could you please help me with this?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

Please don't place information about the story format within the Question's Title, it just pads the title and serves on real purpose if you have correctly tagged your question. (like you have).

You haven't included the TwineScript that shows how you are displaying the initial Stats values, but based on the fact you are passing a ?str hook name to your (replace:) macro I will assume that you have have marked the values using named hooks.

If so then your code should work as demonstrated by the following example.

(set: $str to 10, $statchoice to 10)

Strength: [$str]<str|

(link-repeat: "Strength + 5")[{
	(set: $str to it + 5)
	(set: $statchoice to it - 1)
	(replace: ?str)[$str]
	(if: $statchoice is 0)[
		(goto: "CharacterDev5")
	]
}]


I don't know if you will need to update multiple stats at the same time but if you will then I suggest abstracting the displaying of the stats to a child Passage and then using a (replace:) macro to update all the stats at once.

1. The Stats passage

Strength: $strength
Stamina: $stamina
Agility: $agility

2. The passage with the (link:) that changes the stat values.

{
<!-- The following intital values would actually be assigned in your story's startup tagged special passage, but for demostration purposes they are done here instead. -->
(set: $strength to 10, $stamina to 10, $agility to 10)
}

Stats:
[(display: "Stats")]<stats|

(link-repeat: "Do weigh training")[{
	(set: $strength to it + 5)
	(set: $stamina to it + 2)
	(replace: ?stats)[(display: "Stats")]
}]

 

...