Code Lua
-- Lua Basics
-- I made this because I'm bored.
-- 1. Variables
-- (1.1) Local Variables
local newVariable = "Something"
local newVariable2 = 1
local newVariable3 = true
-- (1.2) Global Variables
newVariable4 = "Insert text here"
-- 2. Tables
local newTable = {"Apple", "Pencil", "Eraser"}
-- 3. If Statement
if 1 + 1 == 2 then
print("Cool, you didn't fail math.")
end
-- 4. for loops
for i = 1, 3 do
print("Successfully looped " .. i .. " times.")
end
-- 5. While loops, break
local i = 1
while true do
i = i + 1
if i == 10 then
break -- Basically exits the loop
end
end
-- 6. Functions
local function newFunction()
print("yes")
end
newFunction()
-- "n" and "n2" are parameters
local function addNumbers(n, n2)
print(n + n2)
end
addNumbers(3, 4) -- prints 7
-- 7. varargs
function Plus(...)
local result = 0
for _, value in ipairs({...}) do
result = result + value
end
return result
end
print(Plus(7, 5, 2, 5)) -- prints 19
print(Plus(1, 2, 3, 4, 5, 6, 7, 8, 9)) -- prints 45
Akari