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 print all elements table Read More

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 multiline string Read More

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 metatable Read More

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 math.random Read More