Difference between revisions of "Basic lua: Types"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
(Undo revision 10856 by AFRLme (talk))
Line 6: Line 6:
 
| class="i_arrow clickablecell" | [[basic_lua:_Tables|>]]
 
| class="i_arrow clickablecell" | [[basic_lua:_Tables|>]]
 
|}
 
|}
 +
== Types ==
 +
{| class="ts"
 +
|-
 +
| boolean || width="90%" | 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.
 +
|}
  
== Types ==
 
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''Boolean''': This returns a value of '''true''' or '''false'''. !!
+
! boolean: This returns a value of '''true''' or '''false'''. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 21: Line 35:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''Function''': A function usually contains a list of actions to be executed & can often be used to calculate & return values. !!
+
! function: A function usually contains a list of actions to be executed & can often be used to calculate & return values. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 34: Line 48:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''Nil''': If no data type is returned then whatever you queried is either empty or does not exist, thus it is '''nil'''. !!
+
! nil: If no data type is returned then whatever you queried is either empty or does not exist, thus it is '''nil'''. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 46: Line 60:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''Number''': This usually contains an integer (whole) or floating point (decimal) number. !!
+
! number: This usually contains an integer (whole) or floating point (decimal) number. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 59: Line 73:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''String''': This usually contains text or numbers wrapped in "quotation marks" or 'apostrophes'. !!
+
! string: This usually contains text or numbers wrapped in "quotation marks" or 'apostrophes'. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">
Line 70: Line 84:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
! '''Table''': This usually consists of an array, or multiple arrays of data & data types. !!
+
! table: This usually consists of an array, or multiple arrays of data & data types. !!
 
|-
 
|-
 
| <syntaxhighlight lang="lua">
 
| <syntaxhighlight lang="lua">

Revision as of 01:42, 3 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.
boolean: This returns a value of true or false.
local a = true

print( a, type(a) )
Basic lua (types) 1.png
function: A function usually contains a list of actions to be executed & can often be used to calculate & return values.
function a(i)
 return i
end

print( a(7), type(a) )
Basic lua (types) 2.png
nil: If no data type is returned then whatever you queried is either empty or does not exist, thus it is nil.
local a = nil

print( a, "  type = " .. type(a) )
print( b, "  type = " .. type(b) )
Basic lua (types) 3.png
number: This usually contains an integer (whole) or floating point (decimal) number.
local a = 7
local b = 7.25

print( a, type(a) )
print( b, type(b) )
Basic lua (types) 4.png
string: This usually contains text or numbers wrapped in "quotation marks" or 'apostrophes'.
local a = "hello world"

print( a, type(a) )
Basic lua (types) 5.png
table: This usually consists of an array, or multiple arrays of data & data types.
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 >

Contents