I am doing a small betting game where you have a balance. I made it so if you win, it would <<set $balance to $balance += $moneybet>> (I also did this as + instead of +=)
When I do this, it does not add the variables together, it adds them onto each other. (ex. If my balance was 10 and the money I bet was 5, instead of adding them to 15 it would make them 105)
Is there another macro, or am I doing the expressions wrong?
Please let me know.
Comments
If that was the case then the issue is that you are assigning String values (a value delimited with quotes) to your variables instead of using Numerical values.
note: If you want to use the += operator then the syntax would be:
There are a number of issues that need to be solved for this to work:
1. A value (even one containing just numbers) entered into a <<textbox>> macro is a String, so you will need to convert that value to a number.
2. The Reader may enter no value or one that contains letters or punctuation (excluding a decimal point) , neither of which can be converted into a number.
The following uses a Javascript isNaN() function and a parseFloat() function to handle checking if the String value is a valid number and converting the String value to a Number, there are other validations that could also be done.