0 votes
by (510 points)
I have the (set:) macro to add a certain number to a variable, but the variable will stay the same until the next passage. How do I fix this?

1 Answer

0 votes
by (156k points)
selected by
 
Best answer

...but the variable will stay the same until the next passage

I believe you are confusing the current value of the variable with the value that is displayed when you 'print' it on the page.

1. The current value of a variable changes if you apply a (set:) macro to it, as demonstrated in following example.

(set: $var to 5)\
initial var: $var

(set: $var to it + 5)\
changed var: $var


2. If you display a variable's value on the page using either the (print:) macro or directly then the displayed value won't change when the variable's value does because there is not association between the displayed value and the variable. You will need to manually re-display the variable's value if you want the displayed value to change, and how you do this depends on how you updated the variable's value.

The following example uses a named hook to mark where the value is on the page and a (replace:) macro to update the displayed value when the variable's value is changed.

(set: $health to 10)

health: |health>[$health]

(link: "Increase Health")[{
	(set: $health to it + 10)
	(replace: ?health)[$health]
}]

 

by (510 points)
Thank you! This worked like a charm! Thank you for all your help!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...