Difference between revisions of "Basic lua: Operators"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Conditional Operators)
Line 13: Line 13:
  
  
Example 1: <span class="blue">if</span> condition is <span style="color:green">true</span>...
+
Example 1: if condition is true (method 1)
 
{| style="width:100%"
 
{| style="width:100%"
 
|-
 
|-
Line 19: Line 19:
 
local a = true
 
local a = true
  
if a then  
+
if a then
 
  print("a = true")
 
  print("a = true")
else
 
print("a = false")
 
 
end
 
end
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_001.png|thumb|right|180px|click to enlarge]]
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_001.png|thumb|right|180px|click to enlarge]]
 
|}
 
|}
  
Example 2: <span class="blue">if</span> condition is <span style="color:green">true</span>... (alternative)
+
Example 2: if condition is true (method 2)
 
{| style="width:100%"
 
{| style="width:100%"
 
|-
 
|-
Line 35: Line 33:
 
if a == true then
 
if a == true then
 
  print("a = true")
 
  print("a = true")
else
 
print("a = false")
 
 
end
 
end
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_002.png|thumb|right|180px|click to enlarge]]
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_002.png|thumb|right|180px|click to enlarge]]
 
|}
 
|}
  
Example 3: <span class="blue">if</span> condition is not <span style="color:green">true</span> do <span class="blue">else</span>...
+
Example 3: if condition is false (method 1)
 
{| style="width:100%"
 
{| style="width:100%"
 
|-
 
|-
Line 47: Line 43:
 
local a = false
 
local a = false
  
if a then
+
if not a then
print("a = true")
 
else
 
 
  print("a = false")
 
  print("a = false")
 
end
 
end
Line 55: Line 49:
 
|}
 
|}
  
Example 4: <span class="blue">if</span> a is 1 is <span style="color:blue">elseif</span> a is 2 do...
+
Example 4: if condition is false (method 2)
 
{| style="width:100%"
 
{| style="width:100%"
 
|-
 
|-
 
| <syntaxhighlight>
 
| <syntaxhighlight>
local a = 1
+
local a = false
  
if a == 1 then
+
if a == false then
  print("a = 1")
+
  print("a = false")
elseif a == 2 then
 
print("a = 2")
 
 
end
 
end
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_004.png|thumb|right|180px|click to enlarge]]
 
</syntaxhighlight> || width="200px" | [[File:lb_operators_004.png|thumb|right|180px|click to enlarge]]
 
|}
 
|}

Revision as of 14:50, 20 August 2014

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

Conditional Operators

if 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 (method 1)

local a = true

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

Example 2: if condition is true (method 2)

local a = true

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

Example 3: if condition is false (method 1)

local a = false

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

Example 4: if condition is false (method 2)

local a = false

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