Lua

up:: Programming ⚐

Basic init.lua

Snippets

Variables

test = 10 --number
isThePlayerAlive = true --Boolean (true, false)
AString = "Anything you want" --String
print(test)

Tables

Test = {} -- Telling Lua it's table
Test = [1] -- Access position 1 in the table
Test = [2] -- Position 2
 
Test[1] = {} -- Making Position 1 into a table

Loops

-- FOR LOOP
for i = 1 , 100 do --Start at 1 until it becomes 100
	print("Hello World!")
end
 
-- WHILE LOOP
counter = 0
while counter < 100 do
	counter = counter + 1
end
 
-- FOR K , V IN PAIRS
Table = {}
Table[1] = "Hello World!"
Table[2] = "Sup!"
Table[3] = "All good!"
 
for key , value in pairs(Table) do
-- loops over all pieces of data in a table
	print(key , value) 	-- key is indentifier: [1], [2]
						-- value is value: "Hello World!"
end

Functions

Functions don’t do anything unless you call on them.

function anyName(a , b)
	sum = a + b
	
	return sum
end
 
test = anyName(10 , 20)
print(test)
  • function
  • anyName - Name of the function
  • (a , b) - Parameters (can be empty)
  • sum = a + b
  • return sum - function ignores everything after `return“
  • test = anyName(10 , 20) - calling on the function with variables 10 , 20
  • print(test) - Printing the output of calling on the function