PlayBasic Variable Tutorial

Variables are fundamental to game programming. This tutorial is an introduction to variables in PlayBasic

## PlayBasic Variable Tutorial

A variable is a box that holds data. Data is information such as how many hit points the player has or the character's name. In PlayBasic, data comes in three different flavors :

• String Data - Used for messages, names, and other things that are composed of text.
• Integer Data - Whole numbers such as 2, 3, 3934, or -234
• Floating Point Data - Numbers that have a decimal point : 42.24, -42.24, etc.

Variables can only hold one kind of data. Which kind of data you use will depend on your needs. For example, you will want to store character names in string variables and their hit points in integer variables. You'll see uses for floating point variables in later tutorials.

You can create a variable by giving it a value like this :

````HitPoints = 150`
```

After the code above is executed, the variable named HitPoints will be created and given the value 150. Once this has been done you can do other things with the variable, like display it's value :

``````HitPoints = 150
Print HitPoints
Sync
WaitKey
End```
```

You can also perform math on the variable, if it is an integer or floating point variable :

``````HitPoints = 150 + 10
Print HitPoints
Sync
WaitKey
End```
```

You can tell what data type a variable contains by it's ending. Variables holding integers require no special ending. String variables end in a dollar sign ( someString\$ ) and floating point variables end in the "pound" sign ( someFloat# )

``````characterName\$ = "Picone"
probability  = 0.5
Print characterName\$
Print probability
Sync
WaitKey
End```
```

## Conclusion

See, variables are really simple. Here's a review :

• You create a variable by giving it a value.
• There are three kinds of data and therefore
• …there are three kinds of variables.
• Integer variables require no special ending
• String variables end with a dollar sign ( \$ )
• Floating point variables end with a ( # )
page revision: 10, last edited: 24 Aug 2007 13:10