로블록스 게임제작

코루틴

Dean83 2024. 2. 14. 09:11

Lua 스크립트에도 코루틴이 존재 한다. 유니티와 비슷하지만 다르다. 

 

함수 작성 -> 코루틴 생성 -> resume 으로 코루틴 실행 의 과정을 거친다. 

 

보통은 무한반복하여 특정 조건을 검색할때 많이 사용되므로 해당 예제를 기록해 둔다. 

 

local function myCoroutine()
    while true do
        print("Coroutine is running")
        wait(1) -- 1초 대기
    end
end

local myCoroutineThread = coroutine.create(myCoroutine)

coroutine.resume(myCoroutineThread) -- 코루틴 시작