Limit the Value of a Variable in PlayBasic
How to Limit the Value of a Variable in PlayBasic
Limiting the value of a variable involves two steps.
- Check to see if the variable has exceeded the limit.
- If it has, set it back to the limit.
This can be used for max hit points, a maximum speed, etc. Naturally, you can limit the value of the variable in both an upper and lower threshold.
Both steps are represented in the code below :
If someVar > 10 Then someVar = 10
ForceDeclaration Declaration someVar EndDeclaration someVar = 42 If someVar > 10 Then someVar = 10 If someVar < 0 Then someVar = 0 Print someVar Sync WaitKey
page revision: 8, last edited: 15 Jul 2012 02:28