Quick Links: Download Gideros Studio | Gideros Documentation | Ultimate Guide | Gideros Development Center
Using the < > and > < custom Gideros operators. - Gideros Forum

Using the < > and > < custom Gideros operators.

SinisterSoftSinisterSoft Maintainer
edited September 21 in Code snippets
The Gideros version of Lua has some extra operators not present in regular Lua.

Two of them are <> and >< (remember these are custom to Gideros Lua)

<> is used to compare two numbers and return the greater of them
>< is used to compare two numbers and return the lesser of them

You may not think so initially, but these are two really handy operators and can save your game both a lot of code and cpu time.

eg:

Instead of this:
pos=10
function gameLoop(e)
x=x-1
if x<5 then x=5 end
print(x)
.
.


You can put this:
pos=10
function gameLoop(e)
x=(x-1)<>5
print(x)
.
.


Both of these routines will produce:
9
8
7
6
5
5
5 and so on...
To limit a number going up just use the other operator:
pos=10
function gameLoop(e)
x=(x+1)><15
print(x)
.
.


This will produce:
11
12
13
14
15
15
15 and so on...

Comments

Sign In or Register to comment.