메뉴 건너뛰기

창작에 관련된 질문이나 간단한 팁, 예제를 올리는 곳

or 연산자를 사용한다.

예제 코드:

function moveplayer(direction)
    direction = direction or "nowhere"
    print("player moved to ".. direction)
end

moveplayer() --> "player moved to nowhere"
moveplayer("north") -- "player moved to north"

이런 코드를 짜지 않고 훨씬 우아하게 처리할 수 있음:

function moveplayer(direction)
    if direction == nil then direction = "nowhere" end
    print("player moved to ".. direction)
end
분류 :
조회 수 :
35
등록일 :
2020.11.06
20:29:41 (*.127.102.18)
엮인글 :
게시글 주소 :
https://hondoom.com/zbxe/index.php?mid=study&document_srl=818611
List of Articles