Difference between revisions of "Basic lua: Types"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 23: Line 23:
 
| <span class="vsyellow">table</span> || This usually consists of an array, or multiple arrays of data & data types.
 
| <span class="vsyellow">table</span> || This usually consists of an array, or multiple arrays of data & data types.
 
|}  
 
|}  
<hr>
+
 
 +
=== Boolean ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! boolean !!
+
! returns true !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 34: Line 35:
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_1.png|frameless|center|180px]]
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_1.png|frameless|center|180px]]
 
|}
 
|}
<hr>
+
 
 +
=== Function ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! function !!
+
! returns 7 !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 47: Line 49:
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_2.png|frameless|center|180px]]
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_2.png|frameless|center|180px]]
 
|}
 
|}
<hr>
+
 
 +
=== nil ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! nil !!
+
! returns nil !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 59: Line 62:
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_3.png|frameless|center|180px]]
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_3.png|frameless|center|180px]]
 
|}
 
|}
<hr>
+
 
 +
=== Number ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! number !!
+
! returns 7 & 7.25 !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 72: Line 76:
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_4.png|frameless|center|180px]]
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_4.png|frameless|center|180px]]
 
|}
 
|}
<hr>
+
 
 +
=== String ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! string !!
+
! returns hello world !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 83: Line 88:
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_5.png|frameless|center|180px]]
 
</syntaxhighlight> || width="180px" style="vertical-align:middle;" | [[File:Basic_lua_(types)_5.png|frameless|center|180px]]
 
|}
 
|}
<hr>
+
 
 +
=== Table ===
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! table !!
+
! returns 1, 2, 3, 4, 5, 6, 7, 8 !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">

Revision as of 02:12, 3 September 2022

< Index >

There are multiple lua types available, which are automatically determined by the returned value of the variable, function or table.

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.

Boolean

returns true
local a = true

print( a, type(a) )
Basic lua (types) 1.png

Function

returns 7
function a(i)
 return i
end

print( a(7), type(a) )
Basic lua (types) 2.png

nil

returns nil
local a = nil

print( a, "  type = " .. type(a) )
print( b, "  type = " .. type(b) )
Basic lua (types) 3.png

Number

returns 7 & 7.25
local a = 7
local b = 7.25

print( a, type(a) )
print( b, type(b) )
Basic lua (types) 4.png

String

returns hello world
local a = "hello world"

print( a, type(a) )
Basic lua (types) 5.png

Table

returns 1, 2, 3, 4, 5, 6, 7, 8
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) )
Basic lua (types) 6.png
< Index >