Chapter 2: Your Boe-Bot’s Servo Motors · Page 73
anotherValue VAR Word
These commands are examples of initializing variables to values that you determine.
After these two commands are executed,
value will store 500, and anotherValue will
store 2000.
value = 500 ' Initialize variables
anotherValue = 2000
These DEBUG commands help you see what each variable stores after you initialize them.
Since
value was assigned 500 and anotherValue was assigned 2000, these DEBUG
commands send the messages “value = 500” and “anotherValue = 2000” to the Debug
Terminal.
DEBUG ? value ' Display values
DEBUG ? anotherValue
The DEBUG command’s “?” formatter can be used before a variable to make the Debug
Terminal display its name, the decimal value it’s storing, and a carriage return. It’s very
handy for looking at the contents of a variable.
The riddle in the next three lines is, what will be displayed? The answer is that
value
will be set equal to ten times
anotherValue. Since anotherValue is 2000, value will
be set equal to 20,000. The
anotherValue variable is unchanged.
value = 10 * anotherValue ' Perform operations
DEBUG ? value ' Display values again
DEBUG ? anotherValue
Your Turn – Calculations with Negative Numbers
If you want to do calculations that involve negative numbers, you can use the DEBUG
command’s
SDEC formatter to display them. Here’s an example that can be made by
modifying VariablesAndSimpleMath.bs2.
√ Delete this portion of VariablesAndSimpleMath.bs2:
value = 10 * anotherValue ' Perform operations
DEBUG ? value ' Display values again
√ Replace it with the following: