Built-in

λ””ν† λžœλ“œμ—μ„œ μ§€μ›ν•˜λŠ” 루아 κΈ°λŠ₯μ΄μ—μš”.

ν•¨μˆ˜

void print(string Text)

λ‘œκ·Έμ°½μ— λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•΄μš”. (좜λ ₯ν•  λ‚΄μš©)

-- μƒ˜ν”Œ --

--λ¬Έμžμ—΄(λ©”μ‹œμ§€)을 λ‘œκ·Έμ°½μ— 좜λ ₯ν•΄μš”.
print("Hello World!")

--.. 을 μ΄μš©ν•΄μ„œ 각각의 λ¬Έμžμ—΄μ„ ν•©μ³μ„œ λ©”μ‹œμ§€λ₯Ό λ‘œκ·Έμ°½μ— 좜λ ₯ν•΄μš”.
print("Hello " .. "Dito" .. "Land!")

--μˆ«μžλ‚˜ bool λ“±μ˜ μžλ£Œν˜•λ„ 좜λ ₯ν•  수 μžˆμ–΄μš”.
print(1)
print(1.5)
print(false)
print(Vector.new(50, 0, 5))
print(Color.new(255, 255, 255, 255))

--μ‹€μˆ˜λŠ” math.floor둜 μ •μˆ˜λ‘œ λ³€ν™˜ν•΄μ„œ 좜λ ₯ν•  수 μžˆμ–΄μš”.
print(math.floor(6.529))

--λ³€μˆ˜μ— μ €μž₯ν•œ 값도 좜λ ₯ν•  수 μžˆμ–΄μš”.
local SomeNumber = 5
local FloorTransform = Workspace.Floor.Transform
print(SomeNumber)
print(FloorTransform)

--μ‰Όν‘œλ₯Ό μ΄μš©ν•΄μ„œ μ—¬λŸ¬ 값을 좜λ ₯ν•  수 μžˆμ–΄μš”.
print(1, " / ", 50.2, " / ", "Hello", " / ", true, " / ", Vector.new(50, 0, 10))

void Log(string Text)

λ‘œκ·Έμ°½μ— 일반 λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•΄μš”. (좜λ ₯ν•  λ‚΄μš©)

-- μƒ˜ν”Œ --

Log("Log")

void LogWarning(string Text)

λ‘œκ·Έμ°½μ— μ›Œλ‹ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•΄μš”. (좜λ ₯ν•  λ‚΄μš©)

-- μƒ˜ν”Œ --

LogWarning("Warning")

void LogError(string Text)

λ‘œκ·Έμ°½μ— μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•΄μš”. (좜λ ₯ν•  λ‚΄μš©)

-- μƒ˜ν”Œ --

LogError("Error")

number time()

κ²Œμž„μ˜ κ²½κ³Ό μ‹œκ°„μ„ 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local startTime = time()

print("wait 3s")
wait(3)

local passTime = time() - startTime
print(passTime)

number ostime()

OS μ‹œκ°„μ„ 얻을 수 μžˆμ–΄μš”. 1970λ…„ 1μ›” 1일 0μ‹œ 0λΆ„ 0초λ₯Ό 기점으둜 ν˜„μž¬κΉŒμ§€ 흐λ₯Έ μ‹œκ°„μ„ μ΄ˆλ‹¨μœ„λ‘œ λŒλ €μ€λ‹ˆλ‹€.

-- μƒ˜ν”Œ --

local getTime = ostime()
print(getTime)

DateTime nowtime()

ν˜„μž¬ μ‹œκ°„μ„ 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getTime = nowtime()
print(getTime)

DateTime ToDateTime()

OsTime으둜 λΆ€ν„° DateTimeλ₯Ό μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getOsTime = ostime()
local Date = ToDateTime(getOsTime)

number ToOsTime()

Date으둜 λΆ€ν„° OsTimeλ₯Ό μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getDate = nowtime()
local getOsTime = ToOsTime(getDate)

number GetDayOfYear()

Date으둜 λΆ€ν„° μ˜¬ν•΄ κΈ°μ€€ 경과일을 μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getDate = nowtime()
local DayOfYear = GetDayOfYear(getDate)

number GetWeekOfYear()

Date으둜 λΆ€ν„° μ˜¬ν•΄ κΈ°μ€€ μ£Όμ°¨λ₯Ό μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getDate = nowtime()
local WeekOfYear = GetWeekOfYear(getDate)

number GetNumberOfWeek()

Date으둜 λΆ€ν„° 이번 μ£Ό κΈ°μ€€μœΌλ‘œ μš”μΌ 번호 λ°˜ν™˜μ„ μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local getDate = nowtime()
local NumberOfWeek = GetNumberOfWeek(getDate)

bool IsChangedYear()

λΉ„κ΅ν•˜λŠ” Dateκ°€ λ‹€μŒ 해인지 μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local ChangedYear = IsChangedYear(T1,T2)

bool IsChangedMonth()

λΉ„κ΅ν•˜λŠ” Dateκ°€ λ‹€μŒ 월인지 μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local ChangedMonth = IsChangedMonth(T1,T2)

bool IsChangedDay()

λΉ„κ΅ν•˜λŠ” Dateκ°€ λ‹€μŒ 날인지 μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local ChangedDay = IsChangedDay(T1,T2)

bool IsChangedWeek()

λΉ„κ΅ν•˜λŠ” Dateκ°€ λ‹€μŒ 주인지 μ–»μ–΄ 올 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local ChangedWeek = IsChangedWeek(T1,T2)

number GetCompareYear()

두 λ‚ μ§œμ˜ 차이 년을 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareYear = GetCompareYear(T1,T2)

number GetCompareMonth()

두 λ‚ μ§œμ˜ 차이 달을 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareMonth = GetCompareMonth(T1,T2)

number GetCompareDay()

두 λ‚ μ§œμ˜ 차이 일을 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareDay = GetCompareDay(T1,T2)

number GetCompareHour()

두 λ‚ μ§œμ˜ 차이 μ‹œκ°„μ„ 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareHour = GetCompareHour(T1,T2)

number GetCompareMinute()

두 λ‚ μ§œμ˜ 차이 뢄을 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareMinute = GetCompareMinute(T1,T2)

number GetCompareSec()

두 λ‚ μ§œμ˜ 차이 초λ₯Ό 얻을 수 μžˆμ–΄μš”.

-- μƒ˜ν”Œ --

local T1 = DateTime.new(2022, 12, 31, 11, 20, 34)
local T2 = DateTime.new(2023, 01, 01, 11, 20, 34)
local CompareSec = GetCompareSec(T1,T2)

ModuleObject require(ObjectScript ModuleScript)

λͺ¨λ“ˆ κΈ°λŠ₯을 μ‚¬μš©ν•  수 있게 λ‘œλ“œν•΄μš”. (λͺ¨λ“ˆμŠ€ν¬λ¦½νŠΈ) (슀크립트 처음 λΆ€λΆ„μ—μ„œ ν•œλ²ˆλ§Œ μž‘μ„±ν•˜λŠ” 것을 ꢌμž₯ν•©λ‹ˆλ‹€.)

-- μƒ˜ν”Œ --

local Utility = require(ScriptModule.DefaultModules.Utility)

void assert(bool condition)

condition 값이 false이면 μ—λŸ¬λ₯Ό 좜λ ₯ν•΄μš”. (쑰건 κ°’)

-- μƒ˜ν”Œ --

local MakeError = false

print("a")
assert(MakeError) --μΈμžκ°€ trueκ°€ μ•„λ‹ˆλ©΄ μ—λŸ¬λ₯Ό 좜λ ₯ν•˜κ³ , λ‹€μŒ 쀄을 μ²˜λ¦¬ν•΄μš”.
assert(MakeError, "Some Error!!") --λ‘λ²ˆμ§Έ μΈμžμ— μ—λŸ¬μ‹œ 좜λ ₯ν•  λ‚΄μš©μ„ 넣을 수 μžˆμ–΄μš”.
print("b")

void wait(number Time)

μ§€μ •ν•œ μ‹œκ°„λ§ŒνΌ κΈ°λ‹€λ €μš”. (λŒ€κΈ°μ‹œκ°„)

-- μƒ˜ν”Œ --

print("wait 3s")
wait(3)
print("end wait!")

void waitbool(function TargetFunction)

ν•¨μˆ˜μ˜ λ°˜ν™˜κ°’μ΄ trueκ°€ λ λ•ŒκΉŒμ§€ ν•¨μˆ˜λ₯Ό 계속 ν˜ΈμΆœν•΄μš”. (ν˜ΈμΆœν•  ν•¨μˆ˜)

-- μƒ˜ν”Œ --

local hour = 1
local function IsMorning()
    if hour < 20 then
        print("It's Morning!")
        hour = hour + 1
        return false
    else
        print("It's Night!")
        return true
    end
end
waitbool(IsMorning) --ν•¨μˆ˜μ˜ λ°˜ν™˜κ°’μ΄ trueκ°€ λ λ•ŒκΉŒμ§€ ν•¨μˆ˜λ₯Ό 계속 ν˜ΈμΆœν•΄μš”

void waitfunction(function TargetFunction)

ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•œ λ’€,ν•¨μˆ˜κ°€ μ’…λ£Œλ  λ•ŒκΉŒμ§€ κΈ°λ‹€λ €μš”. (ν˜ΈμΆœν•  ν•¨μˆ˜)

-- μƒ˜ν”Œ --

print("Call WaitMessage Function")

local function WaitMessage()
    print("wait 3s")
    wait(3)
    print("Hello DitoLand!")
end
waitfunction(WaitMessage) --ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•œ λ’€, ν•¨μˆ˜κ°€ μ’…λ£Œλ  λ•ŒκΉŒμ§€ κΈ°λ‹€λ €μš”

print("End WaitMessage Function")

coroutine create(function TargetFunction)

코루틴을 μƒμ„±ν•΄μš”.

-- μƒ˜ν”Œ --

local co = coroutine.create(function()
    print("Hello!")
end)

void resume(coroutine coroutine)

코루틴을 μ‹€ν–‰ν•΄μš”.

-- μƒ˜ν”Œ --

local co = coroutine.create(function()
    print("Hello!")
end)
coroutine.resume(co)

void yield()

싀행쀑인 코루틴을 μΌμ‹œμ •μ§€ν•΄μš”. (코루틴 μ•ˆμ—μ„œ μ‚¬μš©ν•΄μ•Ό ν•΄μš”.)

-- μƒ˜ν”Œ --

local co = coroutine.create(function()
    for i = 1, 3 do
        print("num : " .. i)
        coroutine.yield()
    end
end)
coroutine.resume(co) -- num : 1
coroutine.resume(co) -- num : 2
coroutine.resume(co) -- num : 3

void wrap(function TargetFunction)

ν•¨μˆ˜μ²˜λŸΌ λ°”λ‘œ ν˜ΈμΆœν•  수 μžˆλŠ” 코루틴을 μƒμ„±ν•΄μš”.

-- μƒ˜ν”Œ --

local co = coroutine.wrap(function()
    print("Hello!")
end)
co()

string status(coroutine coroutine)

μ½”λ£¨ν‹΄μ˜ μƒνƒœλ₯Ό λ°˜ν™˜ν•΄μš”.

-- μƒ˜ν”Œ --

local co = coroutine.create(function()
    print("Hello!")
end)
print(coroutine.status(co)) -- suspend
coroutine.resume(co)
print(coroutine.status(co)) -- dead

Last updated