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... |
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
Comments
Likes: SinisterSoft, pie
https://deluxepixel.com
https://deluxepixel.com
Likes: SinisterSoft
https://deluxepixel.com
a <> b
to find the lesser
a >< b
to convert from degrees to radian
^< a
to convert from radians to degrees
^> a
bitwise operators
a|b bor
a&b and
~a not
a~b xor
a<<b shift a left by b bits
a>>b shift a right by b bits
a//b integer divide use instead of floor(a/b)
macros
pi@3.142 set pi to 3.142 - isn't a variable so it acts like a constant
also the saving/loading of lua byte code is universal between different processor word sizes - eg 32 and 64 bit - unlike regular Lua.
https://deluxepixel.com
Likes: SinisterSoft
Likes: antix, Atavismus
https://deluxepixel.com