Creator Guide
English
English
  • OVERDARE
    • 🚩Introduction to OVERDARE
    • 🐤Get Started
      • OVERDARE App
      • OVERDARE Studio
    • 📌Policy
      • Community Guidelines
      • UGC Creation Guidelines
      • Guidelines on the External Use of UGC
      • Logo Usage Guidelines
      • Intellectual Property Rights Policy
      • Reporting Guidelines
      • Guidelines on Disputing Suspensions and Bans
      • Creator Payout Policy
      • Monetization Guidelines
    • 🅰️OVERDARE Glossary
  • MANUAL
    • 🏰Studio Manual
      • Get Started
        • Studio Interface
        • World Template
        • Coordinate System
        • Studio Test Play
        • World Publish
        • Collaboration
      • Asset & Resource Creation
        • Asset Import
        • Animation Editor
      • Game Development
        • Game Settings
        • Script Editor
        • Align Tool
        • Material Manager
        • Collision Groups
        • Tag Editor
        • Performance Guide
      • Object
        • Part
        • Model
        • Camera
        • Physics
        • Lighting
        • Tool
        • VFX
        • Sound
      • Character
        • Character Animation
        • Humanoid Description
      • GUI
    • 📝Script Manual
      • Get Started
        • Script Overview
        • Basic Guide to Lua
        • Coding Style
        • Object Reference
        • Unity Developer Guide
      • Events & Communication
        • Event
        • Server-Client Communication
        • BindableEvent
        • Value Objects
      • Input & Controls
        • Mobile Input Handling
        • TPS Strafing System
      • Advanced Gameplay Systems
        • Saving & Loading Data
        • Tween
        • Module Script
      • Debugging & Optimization
        • Breakpoint
        • Practical Guide to Script Optimization
  • 💸Monetization
    • Payout Guideline
  • DEVELOPMENT
    • 📚API Reference
      • Enums
        • ActuatorRelativeTo
        • AnimationPriority
        • AspectType
        • AssetTypeVerification
        • BorderMode
        • CameraMode
        • CameraType
        • ContextActionResult
        • CoreGuiType
        • DominantAxis
        • EasingDirection
        • EasingStyle
        • ForceLimitMode
        • HttpCompression
        • HttpContentType
        • HumanoidDisplayDistanceType
        • HumanoidStateType
        • KeyCode
        • Material
        • MaterialPattern
        • NormalId
        • ParticleEmitterShape
        • ParticleEmitterShapeInOut
        • ParticleEmitterShapeStyle
        • ParticleFlipbookLayout
        • ParticleFlipbookMode
        • ParticleOrientation
        • PartType
        • PlaybackState
        • RaycastFilterType
        • RollOffMode
        • RotationType
        • UserInputState
        • UserInputType
        • VelocityConstraintMode
      • DataTypes
        • BlendSpaceSampleSata
        • BrickColor
        • CFrame
        • Color3
        • ColorSequence
        • ColorSequenceKeypoint
        • Content
        • Enum
        • EnumItem
        • NumberRange
        • NumberSequence
        • NumberSequenceKeypoint
        • OverlapParams
        • PhysicalProperties
        • Ray
        • RaycastParams
        • RaycastResult
        • ScriptConnection
        • ScriptSignal
        • TweenInfo
        • Udim
        • Udim2
        • Vector2
        • Vector3
      • Classes
        • Animation
        • AngularVelocity
        • AnimationTrack
        • Animator
        • Atmosphere
        • Attachment
        • Backpack
        • BackpackItem
        • BasePart
        • BaseScript
        • Beam
        • BindableEvent
        • BlendSpace
        • BoolValue
        • Bone
        • Camera
        • CharacterMesh
        • CollectionService
        • Constraint
        • ContextActionService
        • CoreGui
        • DataStore
        • DataModel
        • DataStoreGetOptions
        • DataStoreIncrementOptions
        • DataStoreInfo
        • DataStoreKeyPages
        • DataStoreKeyInfo
        • DataStoreService
        • DataStoreListingPages
        • DataStoreSetOptions
        • FormFactorPart
        • Frame
        • Folder
        • GlobalDataStore
        • GuiBase2d
        • GuiButton
        • GuiObject
        • HttpService
        • Humanoid
        • HumanoidDescription
        • ImageButton
        • ImageLabel
        • InputObject
        • IntValue
        • LayerCollector
        • Instance
        • Light
        • Lighting
        • LinearVelocity
        • LocalScript
        • LuaSourceContainer
        • MaterialService
        • MaterialVariant
        • MeshPart
        • Model
        • ModuleScript
        • Mouse
        • OrderedDataStore
        • Pages
        • Part
        • ParticleEmitter
        • PhysicsService
        • Player
        • PlayerGui
        • Players
        • PlayerScripts
        • PointLight
        • PVInstance
        • ReplicatedStorage
        • RemoteEvent
        • ScreenGui
        • RunService
        • Script
        • ServerStorage
        • ServiceProvider
        • Skeleton
        • ServerScriptService
        • Sound
        • SoundService
        • SoundGroup
        • SpotLight
        • SpawnLocation
        • StarterCharacterScripts
        • StarterPack
        • StarterGui
        • StarterPlayer
        • StarterPlayerScripts
        • StringValue
        • SurfaceGui
        • SurfaceGuiBase
        • Team
        • Teams
        • TextLabel
        • TextButton
        • Tool
        • Trail
        • Tween
        • TweenService
        • TweenBase
        • UIAspectRatioConstraint
        • UserGameSettings
        • UserInputService
        • UserSettings
        • VectorForce
        • Workspace
        • WrapLayer
        • WorldRoot
        • WrapTarget
  • UPDATE
    • 📰Release Note
Powered by GitBook
On this page
  • Overview
  • Comments
  • Code Execution Order
  • Variables
  • Functions
  • local and global
  • Control Statements
  • if
  • goto
  • do
  • Loops
  • for
  • while
  • repeat
  • Logical Operators
  • Tables
  • Coroutines
  1. MANUAL
  2. Script Manual
  3. Get Started

Basic Guide to Lua

Overview

Lua is a lightweight and fast scripting language that 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 = 3

Code 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 intended

Variables

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).

-- Local variable (accessible only within the script where it is declared)
local Num1 = 5
local Num2 = 1.66 
  

-- Global variable (accessible from other scripts as well)
SomeVar = 50
print(SomeVar) -- Prints 50


-- Multiple variable assignments possible
local Text1, Text2 = "A", "B"


-- Assign a function to a variable and call it as a variable
local function SomeFunction()
    print("SomeFunction")
end  

local Func = SomeFunction
Func()

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).

-- If there are more arguments or return values than expected, the extra ones are discarded. If there are fewer, the missing ones are treated as nil.
local function GetVector(x, y, z)
    print("GetVector X", x, "Y", y, "Z", z)
end
GetVector(1, 0)       -- z is nil
GetVector(1, 0, 5, 3) -- Last value is discarded  
  

-- You can return multiple values or use multiple variable assignments.
local function GetVector(x, y, z)
    return x, y, z
end
local x, y, z = GetVecor(1, 0, 1)
  

-- A function's variable arguments are indicated by ...
local function Sum(...)
    local a, b, c = ... -- Missing arguments are treated as nil.
end
Sum(1, 2)
    

-- Variable arguments can also be used with fixed parameters
local function Sum(value, ...)

end

  
-- Return values can also be treated as variable arguments
local function Sum(...)
    return ...
end

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.

A variable/function declared with the global keyword can be accessed from all scripts. 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

if SomeNumber > 0 then 
    print("Positive Number")
    
elseif SomeNumber > 0 then
    print("Negative Number")
    
else
    print("Zero")
end

goto

local SomeValue = 0

::case1:: 
SomeValue = SomeValue + 1
print("SomeValue : ", SomeValue)

if SomeValue == 1 then 
    goto case1 -- Goes back to case1
end

do

local number = 10

do
    local number = 5
    print("number (in do) : ", number)
end

print("number (out do) : ", number)

Loops

Loops are used to repeatedly execute the same block of code until a specific condition is met.

for

-- Starting value, condition, increment
for i = 1, 10, 1 do 
    print(i) 
    break
end   

-- The increment in the for loop is optional and defaults to 1 if omitted.
for i = 1, 20 do 
    print(i)
end

while

local ConditionValue = 0

while ConditionValue < 5 do 
    ConditionValue = ConditionValue + 1
    print(ConditionValue)
    
    if ConditionValue > 3 then
    	break
    end
end

repeat

-- Repeats the code until the condition is true
repeat wait(0.1) until SomeCondition

Logical Operators

Logical operators are used to combine or evaluate conditions in conditional or control statements.

-- Using logical operators inside if statements
if isMonster == true and isBoss == true then 
    print("Monster")
end

if isWalk == true or isRun == true then
    print("On the move")
end

if not isCharacter then 
    print("Not Character")
end  
  

-- Returning values based on conditions
local resultA = a and b -- If the first value is false, return the first value, otherwise return the second value
local resultB = a or b -- If the first value is true, return the first value, otherwise return the second value
local resultC = not a -- Returns true if nil or false

Tables

Tables are complex data structures that store data in key-value pairs, which can also manage data like arrays.

local NumberList = { 1, 2, 3 }
print(#NumberList) -- Returns the size of the table
  

-- Array implementation
local MatrixData = {}
for x = 1, 5 do
    MatrixData[x] = {}
    for y = 1, 2 do
        MatrixData[x][y] = "Coordinate_" .. x .. "x" .. y
        print(MatrixData[x][y])
    end
end  
  

-- Table consisting of Key(Name) and Index(EquipItemIDList)
local MonsterData =
{
    Name = "Orc",
    EquipItemIDList = 
    {
        1, 5, 4
    }	
}
print(MonsterData.Name)
print(MonsterData["Name"])
for i = 1, #MonsterData.EquipItemIDList do
    print(MonsterData.EquipItemIDList[i])
end

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.

print("1")

local printCoroutine = coroutine.create(function()
    wait(2)
    print("2")
end)
coroutine.resume(printCoroutine)

print("3") -- Since the coroutine runs asynchronously, the output will be 1 -> 3 -> 2
PreviousScript OverviewNextCoding Style

Last updated 2 months ago

📝