플레이어 상태
Coddy Lua 여정의 Logic & Flow 섹션에 포함된 레슨 — 54개 중 26번째.
챌린지
쉬움연결된 방들을 바탕으로, 게임 세계에서 플레이어의 현재 위치를 추적할 수 있는 player 테이블을 만드세요.
이전 챌린지에서 사용했던 startingRoom과 gardenRoom 변수가 제공됩니다.
하나의 키를 가진 player라는 이름의 테이블을 만드세요:
currentRoom: 이 키가startingRoom을 참조하도록 설정하세요.
플레이어의 현재 방 이름을 출력한 다음, 플레이어의 현재 방 설명을 별도의 줄에 출력하세요.
예상 출력 형식:
Ancient Library
You find yourself in a dusty library filled with ancient books and scrolls.직접 해보기
-- Create the starting room
local startingRoom = {
name = "Ancient Library",
description = "A dusty library filled with ancient tomes and scrolls.",
exits = {}
}
-- Create the garden room
local gardenRoom = {
name = "Secret Garden",
description = "A hidden garden with overgrown plants and a small fountain.",
exits = {}
}
-- Link the rooms together
startingRoom.exits["east"] = gardenRoom
gardenRoom.exits["west"] = startingRoom
-- Print the required output
print(startingRoom.name)
print(startingRoom.exits["east"].name)
print(startingRoom.exits["east"].exits["west"].name)