- Introduction to lua
- Basic Setup
- Estrela for Luxinia
- Scenegraphs
- Scene Setup
- Models/Meshes
- Input handling
- Basic physics
- Physics surface properties
- Vehicle physics
- Using models
- Picking
- A Simple UDP Server
- GUI for the UDP Server
- Tetris attack clone prototype
- Stencil Shadows
- Sprite animation with matobject
- Project archives
- Estrela for Cg
- Specular mapping shader
- Material and Matobject
Conditions
<< Functions | Lua | Loops >>Conditions are used to check if a certain situation occurs. For example conditions can execute a piece of code that breaks a loop.
Conditions: example
if (false) then print("this will never be printed") end if (true) then print("this will always be printed") elseif (true) then print("this will never be printed") else print("this neither") end if (3+4<10) then print("this is always printed too") end
The example shows how a simple condition is build:
if ( your condition ) then your code endor
if ( your condition ) then your code
else your code that is executed if the
condition was false end
or
if ( your condition ) then your code
elseif ( another condition ) then
code that is executed if the first
condition was false and the second was true
else your code that is executed if the conditions
were false end
Any if or elseif is followed by a then and is finished by a else or end. An else is appended to a if or elseif and must be followed by end.
Of course you can nest as many ifs inside each other as you like:
Example
if (myhatisonfire) then if (theresnowater) then jumponmyhat() else throwhatinwater() end takehatbackonhead() else idle() endThis shows that if you use plain and clear variable names, anybody will understand the code you write - even if not a programmer (well mostly :) ). You should also use functions instead of writing hundreds of lines of code in one condition. This also makes everything clearer and you will understand your code also after some time has passed.
