0 votes
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
by (68.6k 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:

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

// CORRECT
<<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.

...