Packing Your Bag – Variables and Other Containers


Variables aren’t the only kind of container in SenseTalk, and they have some unusual characteristics. Before packing the bag for your adventure it’s a good idea to understand just what sort of container it is!
Like many scripting languages, variables in SenseTalk can be used without declaring them first. Unlike most other languages, if a variable is used before a value has been stored in it, it will evaluate as its name…
put Hello --> Hello
… unless it is a predefined variable. Predefined variables like pi or copyrightSign can be thought of like constants, except that they can be changed if you want (i.e. used as ordinary variables). To see all of the predefined variables, run this command (note: the predefinedVariables is a global property that you can modify):
put the predefinedVariables
Variables are not typed. Any variable can contain any type of value, and a given variable can contain different types of values at different times during a run.
SenseTalk tries to accommodate the user. If a string value is stored in a variable, and that variable is then used in an arithmetic operation, SenseTalk will automatically convert the string value to a number if possible and proceed with the operation.
For more information, see Constants and Predefined Variables