## Lua print contents of table

lua print contents of table for k,v in pairs(table) do print(v) end

## Lua print all elements table

lua print all elements table local people = { { name = “Fred”, address = “16 Long Street”, phone = “123456” }, { name = “Wilma”, address = “16 Long Street”, phone = “123456” }, { name = “Barney”, address = “17 Long Street”, phone = “123457” } } for index, data in ipairs(people) do […]

## Lua numbers

Lua numbers num = 50 — All numbers are doubles.

## Lua nested tables

Lua Nested tables t[2] = {“stuff”, “more stuff”, “even more stuff”} Lua Nested tables someTable[#someTable + 1] = {“newValuea”, “newValueb”};

## Lua multiline string

lua multiline string answer = [[ Multiline strings in Lua do not interpret escape sequences like \n. When running over multiple lines the enters are included, only when the first character is a newline it is ignored. These strings can be nested with = signs between the brackets like multiline comments: [=[This would be a […]

## Lua metatable

lua metatable –[[ Metatables allow you to, among other things, redefine operators. Let’s demonstrate with a simple vector “class”. –]] Vector = {} Vector.mt = {} — The metatable we will be using function Vector.new(x, y) local vec = {} setmetatable(vec, Vector.mt) — “Link” the vector with the metatable vec.x = x vec.y = y […]

## Lua math.random

lua math.random local M = math.random(1,2) –Input you number print(M) lua math.random local randomNumberGenerator = math.random(1,5) if randomNumberGenerator == 1 then print(“1”) elseif randomNumberGenerator == 2 then print(“2”) elseif randomNumberGenerator == 3 then print(“3”) elseif randomNumberGenerator == 4 then print(“4”) elseif randomNumberGenerator == 5 then print(“5”) end

## Lua loops

lua loops while expression do –code end

## Lua loop through table

lua loop through table local Table = {‘Cat’, ‘Dog’, ‘Bird’} for i, v in pairs(Table) do print(i .. ‘ ‘ .. v) end

## Lua local

lua local local name = “jojo” print(“Hello, “..name)