Difference between revisions of "Basic lua: Types"
From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 26: | Line 26: | ||
! Example 1: boolean !! | ! Example 1: boolean !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
local a = true | local a = true | ||
Line 37: | Line 37: | ||
! Example 2: function !! | ! Example 2: function !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
function a(i) | function a(i) | ||
return i | return i | ||
Line 50: | Line 50: | ||
! Example 3: nil !! | ! Example 3: nil !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
local a = nil | local a = nil | ||
Line 62: | Line 62: | ||
! Example 4: number !! | ! Example 4: number !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
local a = 7 | local a = 7 | ||
local b = 7.25 | local b = 7.25 | ||
Line 75: | Line 75: | ||
! Example 5: string !! | ! Example 5: string !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
local a = "hello world" | local a = "hello world" | ||
Line 86: | Line 86: | ||
! Example 6: table !! | ! Example 6: table !! | ||
|- | |- | ||
− | | <syntaxhighlight> | + | | <syntaxhighlight lang="lua"> |
local a = {1,1+1,1*3,2*2,20/4,"6",3.5*2,10-2} | local a = {1,1+1,1*3,2*2,20/4,"6",3.5*2,10-2} | ||
Revision as of 18:31, 2 September 2022
There are multiple lua types available, which are automatically determined by the returned value of the variable, function or table.
< | Index | > |
Types
boolean | This returns a value of true or false. |
function | A function usually contains a list of actions to be executed & can often be used to calculate & return values. |
nil | If no data type is returned then whatever you queried is either empty or does not exist, thus it is nil. |
number | This usually contains an integer (whole) or floating point (decimal) number. |
string | This usually contains text or numbers wrapped in "quotation marks" or 'apostrophes'. |
table | This usually consists of an array, or multiple arrays of data & data types. |
Example 1: boolean | |
---|---|
local a = true
print( a, type(a) )
|
Example 2: function | |
---|---|
function a(i)
return i
end
print( a(7), type(a) )
|
Example 3: nil | |
---|---|
local a = nil
print( a, " type = " .. type(a) )
print( b, " type = " .. type(b) )
|
Example 4: number | |
---|---|
local a = 7
local b = 7.25
print( a, type(a) )
print( b, type(b) )
|
Example 5: string | |
---|---|
local a = "hello world"
print( a, type(a) )
|
Example 6: table | |
---|---|
local a = {1,1+1,1*3,2*2,20/4,"6",3.5*2,10-2}
print( a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], type(a) )
|
< | Index | > |