0 votes
asked by (150 points)
I understand this is either a remarkably stupid or remarkably simple question, but could someone give me an example of a <<set>> macro in which sugarcube does proper arithmetic including various variables?

I've tried a few different ways, but no matter how I do it it simply strings them together. For instance, in an equation where $variable1 is one, $variable2 is two etc: <<set $variable1 to $variable1 + $variable2 + $variable3>> renders $variable1 as 123 instead of 6. Is there a way to write this that would cause it to actually do the math?

1 Answer

0 votes
answered by (60.2k points)
selected by
Best answer

You're obviously either initializing your variables as strings, rather than actual numbers, or doing something to force them to be coerced into strings, so simply stop doing that.  For example:

<<set $variable1 to "1">>
<<set $variable2 to "2">>
<<set $variable3 to "3">>

<<set $variable1 to 1>>
<<set $variable2 to 2>>
<<set $variable3 to 3>>

If that doesn't seem to be what you're doing, then we're going to need to see your code.

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.