TWiki
> Main
>
NumberVariables
Number Variables
This is a variable used to store a number.
Creating a number variable
Right click on State and select 'Add Number'.
In the properties its a good idea to change the name to something meaningful (i.e. something that describes what the variable will store like 'playerAge', or 'currentX'). The default value is 0, but this can be changed in the properties.
Setting the value with code
Setting the value of a number variable in code is fairly straightforward:
myNumberVariable.Value = 42;
You start with the name of your number variable, add a full stop - at which point a pop-up should appear - add 'Value', then an equals sign. You then add the number you want to store and finish with a semi colon. You can also store decimal numbers:
myNumberVariable.Value = 1.61803;
And negative numbers:
myNumberVariable.Value = -17.77;
Accessing the value of a number variable
Simply reference the
Value property of the variable. For example to add two number variables together and assign the result to a third number variable:
theResultNumber.Value = myFirstNumber.Value + mySecondNumber.Value;
A note on number types
Programmers will be aware that storing numbers on a computer is more complex than it may seem. Mscape stores numbers as type
double. In real terms this is unlikely to be significant for most people; though does help to explain why GPS coordinates have so many digits after the decimal point.
Related articles