daterre / Cradle

Play Twine stories in Unity.
MIT License
298 stars 32 forks source link

Incrementing undefined variable causes error #39

Closed BrodyB closed 7 years ago

BrodyB commented 7 years ago

In Twine (at least in Sugarcane), when a set incrementor macro is called like <<set $testVar += 1>> when the variable $testVar has not been previous set, that variable is automatically initialized with the value of 0 and is then incremented.

Currently in Cradle, this generates the line Vars.testVar += 1; which, if testVar hasn't been initialized yet, generates an error: VarTypeException: Cannot combine null with Int32 using Add.

I'm going to look into how this can be achieved, but wondering if you might have any insight into where you think would be a good place to start, @daterre?

daterre commented 7 years ago

Hi, I'll look into a codebase fix, but in the meantime you can workaround this by initializing your variable in a startup passage (named StoryInit in Sugarcube).