Menu
Coddy logo textTech

Player State

Part of the Logic & Flow section of Coddy's Lua journey — lesson 26 of 54.

challenge icon

Challenge

Easy

Building on your linked rooms, create a player table to track the player's current location in the game world.

You are provided with the startingRoom and gardenRoom variables from the previous challenge.

Create a table called player with a single key:

  • currentRoom: Set this to reference the startingRoom

Print the name of the player's current room, then print the description of the player's current room on separate lines.

Expected Output Format:

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

Try it yourself

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

All lessons in Logic & Flow