[GUIDE]: Lua Scripting - The Basics

here is a shitty guide to lua scripting that i have put no effort in. go cry about it.

– console stuff

print(“prints”)
warn(“pretty much just a yellow print”)

– variables

local newBool = false → Bool type
local newInt = 78 → Int type
local newStr = “Hello, world” → Str type

– if, else, else if

– and → self explained: if val1 == 7 and val2 == 7 then return end
– or → self explained: if val1 == 7 or val2 == 7 then return end
– < → less than: if 7 < 8 then return end
– > → greater than: if 7 > 6 then return end
– >= → greater than or equal to: if 7 >= 6+1 then return end
– <= → less than or equal to: if 7 <= 5+1 then return end
– == → equal to: if 7+7 == 14 then return end
– ~= → not equal to: if 7+7 ~= 15 then return end

– examples

if newBool == false then
print(“setting newBool to true and adding 1 to newInt”)
newBool = true
newInt++ – or newInt = newInt + 1
else
print(“setting newBool to false and taking 2 from newInt”)
newBool = false
newInt = newInt - 2
end

if newInt == 79 then
print(“newInt is 79 and this check has passed”)
elseif newInt == 77 then
print(“newInt is 77 and the first check didn’t pass”)
elseif newInt == 78 then
print(“newInt is 78 and the first two checks didn’t pass”)
else
print(“newInt’s value is unknown as none of the checks passed”)
end

– while loops

— this will crash the game. always include a wait() inside the loop
while true do
print(“loop”)
end

— correct
while wait() do
print(“loop”)
end

OR

while true do
print(“loop”)
wait()
end

— wait() can also take a parameter (Int) → wait(1), wait(0.1), wait(10)

– functions

function addInteger(a, b)
print(a + b)
return
end

— a function can also be placed in a variable

local func2 = function
print(“this function is inside a variable”)
return
end

– calling a function

addInteger(1, 2)


— more advanced things will be in the next guide → for loops, game services, math, other stuff maybe