So I've been messing with twine the past couple of days, fun thing to learn I must say.
But horribly annoying when it comes to troubleshooting what's gone wrong, now a quick explenation of what I've done should be in order. I've made two variables $Stamina and $Magic, both these values are increased and decreased by 1 each click the player does through a small code in the sidebar.
<<if $Options is 1>> /* Time, Magic and Stamina will not increase */
<<else>>
<<set $Time += 1; $Stam -= 1; $Magic += 1>>
<</if>> /* Options if end */
This piece of code runs everytime you click a passage as a way to make progress with each click, this part works fine.
But I made a 'debug' tool to help manage things and with that I made it so that it's possible to change Magic and Stamina with a </span> & <<Textbox>> command
<<if $Statmod is 1>> /* if Statmod */
<span id="STATMODSTAM">
<<click "Change Stamina">>
<<replace "#STATMODSTAM">> <<textbox "$Stam" "10" "Settings">> <</replace>>
<</click>>
</span>
|
<span id="STATMODSTAM">
<<click "Change Magic">>
<<replace "#STATMODSTAM">> <<textbox "$Magic" "10" "Settings">> <</replace>>
<</click>>
</span>
|
<span id="STATMODSandM">
<<click "Change Both">>
<<replace "#STATMODSandM">> <<textbox "$SandM" "10" "Settings">> <</replace>>
<</click>>
</span>
<<if $SandM gt 0>> <<set $Magic to $SandM; $Stam to $SandM; $SandM to 0>> <</if>>
<<endif>> /* if Statmod END */
Basically I can use it to increase/decrease both the the stats $Stam and $Magic, however, after doing so the very first command I showed you, the one that runs in the sidebar partially stops working.
<<set $Magic += 1>>
This one stops adding 1 as a value to the variable, instead adds "1" as a text string to the variable $Magic. Making the number 10 become 101 and for each passage I click, it adds more becoming 1011, 10111 and so fourth.
I'm slowly going crazy trying to figure out why += doesn't work but the -= works just fine. I desperatly need pointers.
Just to add a bit more information, I am using Twine 2 w/ SugarCube 1.0.26.
Edit: This post took almost two weeks to get approved for posting, I no longer need help to this as I change the whole thing to act differently. However, I'll leave it up as I still would like to know why textbox didn't set $Magic as a number.
Comments
For example, since you appear to be forwarding to the passage "Settings" afterward, you may be able to do something like the following at the top of that passage: That will attempt to ensure that each of the $variables is an actual number.
On the other hand, the reason why applying $Magic += 1 to the numeric string afterward did not work as expected is because + is one of three operators: the arithmetic addition operator, the unary plus operator, or the string concatenation operator. The first two only work upon actual numbers, while the latter only works upon strings. Again, in this case you were using the combo += operator, which is either the arithmetic addition assignment operator or the string concatenation assignment operator. Since one of the operands is a string, the system assumes that it should use the string concatenation operator instead of the arithmetic addition operator. Thus, instead of the string operand being coerced into a number for arithmetic addition, the number operand is coerced into a string for string concatenation.
Welcome to the wonderful world of dynamic typing and operator overloading.