? Limit Variable to Range ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Limit Variable to Range

Code like:IF X>maximum THEN X=maximum IF X<minimum THEN X=minimum Can be written as:

<variable>=MIN(MAX(<variable>, minimum), maximum)

Example: X=MIN(MAX(X,0),400) Y=MIN(MAX(Y,0),240) Limits X and Y to the screen limits. Use this instead of: IF X<0 THEN X=0 IF X>399 THEN X=399 IF Y<0 THEN Y=0 IF Y>239 THEN Y=239 I mean you should probably just have checks when you modify your variables
Author
12Me21
Updated
Rating
3 votes
Categories
Keywords
3 Comment(s) 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website I thought I was so clever when I "discovered" this, but it turns out that it's pretty well known in other languages too... randomous randomous Owner Robot Hidden Easter Eggs Second Year My account is over 2 years old Website Drawing I like to draw! Hobbies You can't use italics in a [code] segment. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website Fixed.