Adding to a Variable

After a confusing Coding Session, Coding has done it again and made me feel like a Idiot.
Ive been coding a Combat Phase for a game of mine or Interactive, your giving the Option to buff your Damage by +5. DP1 stands for Damage Points for Party Member 1.
I set up the Following in StoryInit:

Story Init
<<set $DP1 = 10>>

After that I go to the Buff Passage where that member gets the +5, and first tried Remember

<<remember $DP1 += 5>>

$DP1 came out as a [ number NAN ]
I next tried out Set

<<set $DP1 = (DP1 +5)>> and <<set $DP1 += 5>>

I worked until another +5 was added with the last, than it went back to [ number NAN ].

Am I dumb or am I coding something wrong?

<<set $var += 5>> should add 5 to a numerical variable.
There is also <<set $var to $var +5>> as well.
<<remember>> is a deprecated macro (i.e. you shouldn’t use it).

3 Likes

The name and letter-casing of the special Passages is very important, so make sure your StoryInit special Passage is named correctly. The same is true for the names of any Variables you define.

The following is a TWEE Notation based representation of the two Passages you mentioned so far…

:: StoryInit
<<set $DP1 = 10>>

:: Buff
<<set $DP1 += 5>>

…and the above should work if the letter-casing of the Passage & Variable names are correct.

Your <<set $DP1 = (DP1 +5)>> example doesn’t work because the 2nd DP1 reference in it is missing the $ character that indicates that that reference is a Story Variable.

4 Likes

Thanks! I was confused about what wasn’t working. Good to know for future coding with the Remember.