Difference between revisions of "Basic lua: Operators"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Conditional Operators)
Line 1: Line 1:
 
Lua operators are expressions used to perform calculations or to pass arguments between different value types. __NOTOC__
 
Lua operators are expressions used to perform calculations or to pass arguments between different value types. __NOTOC__
 
== Conditional Operators ==
 
== Conditional Operators ==
{| class="tbl-ds"
+
{| class="ts"
 
|-
 
|-
| <span class="blue bold">if</span> || width="90%" | Query if something does or does not meet a certain condition
+
| if | width="90%" | Query if something does or does not meet a certain condition.
 
|-
 
|-
| <span class="blue bold">else</span> || Do something else if the query condition was not met
+
| else || Do something else if the query condition was not met.
 
|-
 
|-
| <span class="blue bold">elseif</span> || Used to add additional if queries, if the initial query condition was not met
+
| elseif || Used to add additional if queries, if the initial query condition was not met.
 
|-
 
|-
| <span class="blue bold">end</span> || This is used to close various queries or functions; there must be the same amount of <span class="blue">end</span> as <span class="blue">if</span> unless <span class="blue">elseif</span> has been used
+
| end || This is used to close various queries or functions; there must be the same amount of '''end''' as '''if'''; except in instances where '''elseif''' has been used/
|} <br/>
+
|}  
 +
 
  
 
Example 1: <span class="blue">if</span> condition is <span style="color:green">true</span>...
 
Example 1: <span class="blue">if</span> condition is <span style="color:green">true</span>...

Revision as of 19:57, 19 August 2014

Lua operators are expressions used to perform calculations or to pass arguments between different value types.

Conditional Operators

width="90%" | Query if something does or does not meet a certain condition.
else Do something else if the query condition was not met.
elseif Used to add additional if queries, if the initial query condition was not met.
end This is used to close various queries or functions; there must be the same amount of end as if; except in instances where elseif has been used/


Example 1: if condition is true...

local a = true

if a then 
 print("a = true")
else
 print("a = false")
end
click to enlarge

Example 2: if condition is true... (alternative)

local a = true

if a == true then
 print("a = true")
else
 print("a = false")
end
click to enlarge

Example 3: if condition is not true do else...

local a = false

if a then
 print("a = true")
else
 print("a = false")
end
click to enlarge

Example 4: if a is 1 is elseif a is 2 do...

local a = 1

if a == 1 then
 print("a = 1")
elseif a == 2 then
 print("a = 2")
end
click to enlarge