Lua Scripting
Variables-
Can store a value
Black = "off white"
print(black)
This will print off white.
This assigns the string 'off white' to the variable 'Black' and prints its value. Variables in Lua are case-sensitive, meaning that 'Black' and 'black' would be treated as different variables.It will grab any value of the variable which is stored.
Can also hold numbers
variables can be equal to other variables as well
black = 7
nie = black
print(nie)
this will print 7 as nie = black = 7can change variable value later
black = 7
nie = black
black = "off - white"
print(nie)
this will still print 7 as nie still holds the old value of black which is 7 as code comes from top to bottomString
words or letters inside “ “ are known as strings
in the above case “off white” is a string
Conditional Statements
Contain - If, Elseif or else
format
black = 7
if black > 0 then
black + 1
endthis will only happen is black is greater than 0
AFTER EVERY LADDER THERE WILL BE ONLY 1 END.
while, for
format
black = 7
while black < 100 do
black + 1
endthis will keep adding 1 till black is equal to 100,
Functions
a section of code which can defined and used elsewhere in the code
format
black = 7
function increaseblack()
black = black + 7
endincreaseblack is the name of the function and if we use that in the code elsewhere it will perform the task inside the function bar
To make use of the function add increaseblack() elsewhere in the code otherwise it will not worked
We can also add another variables value into the ()
black = 7
function increaseblack(s)
black = black + s
end
increaseblack(90)
increaseblack(2)
print(black) you can add multiple variables by adding comas in between
but you would have to
black = 7
function increaseblack(s, d, a)
black = black + s
end
increaseblack(90, 2, 2)
increaseblack(2, 5, 6) -- value of s d and a respectively
print(black) you can also add value to s d and a then change it to blacks perpestive
black = 7
function increaseblack(s)
s = s + 8
return s
end
black = inscreaseblack(10)SO IN THIS CASE 10 IS GOING TO BE PASSED IN AS S, THEN IT WILL BE 10 = 10 + 8
Gobal and Local Variables
GLOBAL CAN BE USED THROUGHTOUT THE ENTIRTY OF THE CODE WHEREAS LOCAL ONLY IN THE SPECIFIED PATH TO MAKE A LOCALVAR- local s = 10 or just local s
Tables
used as {} wherever curly backet is used it means its a table.
black = 7
testTable = {}
testTable[1] = 34 - holds the value of { x, 34, x }
testTable[2] = 22 - holds the value of { x, 22, x }
testTable[3] = 24 - holds the value of { x, 24, x }
black = testTable[1]
print(black)
this will print value of black as 34
FOR EASYNESS
USE
testTable = { 34, 22, 24 }
CAN BE USED IN MAKING LEADERBOARDS
black = 7
testTable = {}
insert.Table(testTable, 95) -- Adds the value of 95 to testable index 1