Welcome!
Today you going to learn functions, variables and basic syntax in
Lua!
Syntax
If you know Python, you will learn Lua very easy,
All because similar syntax in these languages.
Also, cubzh adding some extra rules in Lua for world scripts.
We can write comments in code (in end of the line type -- and any text)
Variables
Variables is a thing that stores value, that can be changed
To create variables in Lua we need this simple code:
variable_name = variable_value
Variable name should start with English lowercase letter
Variable can store all value types that Lua have, here's a list of all:
Value types:
• Number - any number (Example: 5, 5.2)
• String - Text value, should be in " " (Example: "SysFAB")
• Functions - Code parts that can be called later (In next part)
• Tables - Multifunctional type (In next lessons)
• Boolean - true and false, only lowercase
• nil - nothing, default value of any variable, only lowercase
Let's create our first variable!
text = "Hello, world!"
Also we can do math operations with some variables, like:
c = 15 + number_b
If number_b be will be a number, c will be 15 + number_b
Basic functions
Function - Code part that can be called later
In Lua we have some starting functions:
print(value) -- Prints value in game chat
And many others.
Also we can create own functions:
cube = function(x)
return x*x*x
end
When we creating function, we write arguments for it inside function( here )
return its a keyword that returns value.
If we return something, function will be stopped
If we not writing return keyword, function will return nil in end
This is our cube function, it just a variable, but now we can call it:
a = cube(3)
print(a) -- Prints 27 in chat
Thanks for reading this lesson
Next lesson: #1134008017550049360