Creator Guide
Korean
Korean
  • OVERDARE
    • 🚩OVERDARE 소개
    • 🐤시작하기
      • OVERDARE App
      • OVERDARE Studio
    • 📌운영 정책
      • 커뮤니티 가이드라인
      • UGC 콘텐츠 제작 가이드라인
      • UGC의 외부 활용 가이드라인
      • LOGO 활용 가이드라인
      • 지식 재산권 정책
      • 신고 안내
      • 콘텐츠 제재 이의 신청 안내
      • 크리에이터 정산 정책
      • OVERDARE 수익화 가이드라인
    • 🅰️OVERDARE Glossary
  • MANUAL
    • 🏰스튜디오 메뉴얼
      • 시작하기
        • 스튜디오 인터페이스
        • 월드 템플릿
        • 좌표계
        • 스튜디오 테스트 플레이
        • 월드 퍼블리시
        • Collaboration
      • 에셋 & 리소스 제작
        • 에셋 임포트
        • 애니메이션 에디터
      • 게임 제작
        • 게임 설정
        • 스크립트 에디터
        • 정렬
        • Material Manager
        • Collision Groups
        • Tag Editor
        • 퍼포먼스 가이드
      • Object
        • 파트
        • 모델
        • 카메라
        • 물리
        • 조명
        • Tool
        • VFX
        • Sound
      • 캐릭터
        • 캐릭터 애니메이션
        • Humanoid Description
      • GUI
    • 📝스크립트 메뉴얼
      • 시작하기
        • 스크립트 개요
        • 루아 기초 가이드
        • 코딩 스타일
        • 오브젝트 참조
        • 유니티 개발자용 가이드
      • 이벤트 및 통신
        • 이벤트
        • 서버-클라 통신
        • BindableEvent
        • Value Objects
      • 입력 및 조작
        • 모바일 조작 처리
        • TPS Strafing System
      • 게임 고도화
        • Saving & Loading Data
        • 트윈
        • 모듈 스크립트
      • 디버깅 & 최적화
        • 중단점
        • 스크립트 최적화 실전 가이드
  • 💸수익화
    • 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
  • 개요
  • 주석
  • 코드 실행 순서
  • 변수
  • 함수
  • local과 global
  • 제어문
  • if
  • goto
  • do
  • 반복문
  • for
  • while
  • repeat
  • 논리 연산자
  • 테이블
  • 코루틴
  1. MANUAL
  2. 스크립트 메뉴얼
  3. 시작하기

루아 기초 가이드

개요

Lua는 초심자도 쉽게 학습하고 사용할 수 있는 가볍고 빠른 스크립팅 언어로, OVERDARE Studio에서 높은 창작 자유도를 제공하며 다양한 기능 구현에 최적화된 도구로 사용됩니다.

주석

주석은 코드의 기능을 설명하거나, 코드를 실행되지 않게 설정하기 위해 사용합니다.

-- 한줄 주석
local Num1 = 1

--[[
local Num2 = 2
여러줄에 대한 주석
]]--

local Num3 = 3

코드 실행 순서

코드는 위에서 아래로 실행되며, 위쪽에서 아래에 선언된 함수나 변수를 호출할 수 없습니다.

SomeFunc() -- 오류 발생

local function SomeFunc()
    print("SomeFunc")
end
SomeFunc() -- 정상 작동

변수

루아에서는 변수를 선언할때 정수/실수/문자열 등 자료형을 명시하지 않으며, 변수의 범위는 해당 스크립트에서만 접근 가능한 local과 다른 스크립트에서도 접근 가능한 global로 지정할 수 있습니다.

-- 로컬 변수 (선언한 해당 스크립트에서만 접근 가능)
local Num1 = 5
local Num2 = 1.66


-- 전역 변수 (다른 스크립트에서도 접근 가능)
SomeVar = 50
print(SomeVar) -- 50 출력


-- 변수 다중 할당 가능
local Text1, Text2 = "A", "B"


-- 변수에 함수를 할당하고 변수로 호출 가능
local function SomeFunction()
    print("SomeFunction")
end

local Func = SomeFunction
Func()

함수

함수의 범위는 변수와 마찬가지로 해당 스크립트에서만 접근 가능한 local과 다른 스크립트에서도 접근 가능한 global로 지정할 수 있습니다.

-- 함수 인자나 반환값은 정해진 것보다 많으면 버려지고 적으면 nil로 처리된다.
local function GetVector(x, y, z) 
    print("GetVector X", x, "Y", y, "Z", z)
end
GetVector(1, 0)       -- z는 nil
GetVector(1, 0, 5, 3) -- 마지막 값은 버려짐


-- 여러 값을 반환하거나, 변수 다중 할당도 가능
local function GetVector(x, y, z) 
    return x, y, z
end
local x, y, z = GetVecor(1, 0, 1) 


-- 함수의 가변 인자는 ...로 표시
local function Sum(...) 
    local a, b, c = ... -- 부족한 인자는 nil로 처리된다.
end
Sum(1, 2)


-- 가변 인자는 고정 매개변수와 함께 사용하는 것도 가능
local function Sum(value, ...) 

end


-- 반환 값도 가변 인자로 처리 가능
local function Sum(...)
   return ...
end

local과 global

local 키워드를 사용하여 선언된 변수/함수는 해당 변수/함수가 선언된 스크립트에서만 유효하며, 외부에서는 접근할 수 없습니다. 따라서, 동일한 이름의 local 변수/함수가 여러 스크립트에서 사용되더라도 서로 영향을 미치지 않습니다.

global 키워드를 사용하여 선언된 변수/함수는 모든 스크립트에서 접근할 수 있습니다. 단, 같은 이름의global 변수/함수는 하나만 존재할 수 있습니다.

제어문

제어문은 코드의 흐름(실행 순서)을 제어하기 위해 사용됩니다.

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 -- case1로 돌아간다.
end

do

local number = 10

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

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

반복문

반복문은 특정 조건이 충족될 때까지 동일한 코드 블록을 반복 실행하기 위해 사용됩니다.

for

-- 시작값, 조건값, 증가값
for i = 1, 10, 1 do 
    print(i) 
    break
end 

-- for문의 증가값은 생략 가능하며 생략시 1로 처리된다.
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

-- 조건이 true가 될때까지 코드 반복
repeat wait(0.1) until SomeCondition

논리 연산자

논리 연산자는 조건문이나 제어문에서 조건을 결합하거나 판단하기 위해 사용됩니다.

-- if문 안에서 논리 연산자 사용
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


-- 조건에 따른 인자 반환
local resultA = a and b -- 첫번째 인자가 거짓이면 첫인자, 진짜면 두번째 인자 반환
local resultB = a or b  -- 첫번째 인자가 진짜면 첫인자, 거짓이면 두번째 인자 반환
local resultC = not a   -- nil과 false는 true로 반환

테이블

키-값 쌍으로 데이터를 저장할 수 있는 복합 데이터 구조로, 배열과 같은 데이터도 관리할 수 있습니다.

local NumberList = { 1, 2, 3 }
print(#NumberList) -- 테이블의 크기 반환


-- 배열 구현
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


-- Key(Name)와 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

코루틴

코루틴(Coroutine)은 실행을 일시 중단하고 필요한 시점에 다시 재개할 수 있는 기능을 제공합니다. 일반 함수와 달리, 코루틴은 멈췄던 상태를 유지한 채 이어서 실행할 수 있으므로, 비동기 작업이나 복잡한 흐름 제어에 유용합니다.

print("1")

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

print("3") -- 코루틴은 비동기처럼 실행되므로 1->3->2 순으로 출력된다.
Previous스크립트 개요Next코딩 스타일

Last updated 3 months ago

📝