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.

  1. Check to see if the variable has exceeded the limit.
  2. 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

Complete Code

ForceDeclaration

Declaration
    someVar
EndDeclaration

someVar = 42

If someVar > 10 Then someVar = 10
If someVar < 0 Then someVar = 0

Print someVar
Sync
WaitKey
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.