Basic Guide to Lua
Overview
Luau is a lightweight and fast scripting language extended from Lua, which can be easily learned and used even by beginners. In OVERDARE Studio, it serves as an optimized tool for implementing various functionalities while providing high creative freedom.
Comments
Comments are used to explain the functionality of the code or to disable code from running.
-- Single-line comment
local Num1 = 1
--[[
local Num2 = 2
Multi-line comment
]]--
local Num3 = 3Code Execution Order
Code runs from top to bottom, and you cannot call functions or variables declared below from above.
SomeFunc() -- Error occurs
local function SomeFunc()
print("SomeFunc")
end
SomeFunc() -- Works as intendedVariables
In Lua, you do not specify data types like integer, float, or string when declaring a variable. The scope of a variable can be defined as either local (accessible only within the current script) or global (accessible from other scripts).
Functions
Like variables, the scope of a function can be defined as local (accessible only within the current script) or global (accessible from other scripts).
local and global
The variable/function declared with the local keyword is only valid within the script in which it is declared and cannot be accessed externally. Therefore, even if local variables/functions with the same name are used in multiple scripts, they do not affect each other.
Variables or functions declared in the global table (_G) can be accessed from any script. However, only one global variable/function with the same name can exist.
Control Statements
Control statements are used to control the flow (execution order) of the code.
if
goto
The goto statement is not supported.
do
Loops
Loops are used to repeatedly execute the same block of code until a specific condition is met.
for
while
repeat
Logical Operators
Logical operators are used to combine or evaluate conditions in conditional or control statements.
Tables
Tables are complex data structures that store data in key-value pairs, which can also manage data like arrays.
Coroutines
Coroutines provide the ability to pause execution and resume it at a later time. Unlike regular functions, coroutines maintain their state when paused and can continue execution from that point, making them useful for asynchronous tasks or complex flow control.
Luau In-depth Learning
Compared to standard Lua, Luau offers a wide range of advanced features. Refer to the guide below for in-depth learning.
Luau GuideLast updated