Difference between revisions of "Basic lua: Operators"
From The Official Visionaire Studio: Adventure Game Engine Wiki
(→Conditional Operators) |
|||
Line 13: | Line 13: | ||
− | Example 1: | + | 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") | ||
− | |||
− | |||
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: | + | 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") | ||
− | |||
− | |||
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: | + | 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 = false") | print("a = false") | ||
end | end | ||
Line 55: | Line 49: | ||
|} | |} | ||
− | Example 4: | + | Example 4: if condition is false (method 2) |
{| style="width:100%" | {| style="width:100%" | ||
|- | |- | ||
| <syntaxhighlight> | | <syntaxhighlight> | ||
− | local a = | + | local a = false |
− | if a == | + | if a == false then |
− | print("a = | + | print("a = false") |
− | |||
− | |||
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 |
Example 2: if condition is true (method 2)
local a = true
if a == true then
print("a = true")
end |
Example 3: if condition is false (method 1)
local a = false
if not a then
print("a = false")
end |
Example 4: if condition is false (method 2)
local a = false
if a == false then
print("a = false")
end |