Menu
Coddy logo textTech

Stan gracza

Część sekcji Logika i przepływ programu ścieżki Lua w Coddy. Lekcja 26 z 54.

challenge icon

Wyzwanie

Łatwy

Rozbudowując połączone pokoje, utwórz tablicę gracza, aby śledzić jego aktualne położenie w świecie gry.

Otrzymujesz zmienne startingRoom i gardenRoom z poprzedniego wyzwania.

Utwórz tablicę o nazwie player z jednym kluczem:

  • currentRoom: ustaw tę wartość tak, aby wskazywała na startingRoom

Wypisz nazwę aktualnego pokoju gracza, a następnie w osobnym wierszu wypisz opis aktualnego pokoju gracza.

Oczekiwany format wyjścia:

Ancient Library
You find yourself in a dusty library filled with ancient books and scrolls.

Spróbuj swoich sił

-- 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)

Wszystkie lekcje w sekcji Logika i przepływ programu

Poćwicz samodzielnie: Kompilator Lua online