Menu
Coddy logo textTech

The Game Loop

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

challenge icon

Challenge

Easy

Implement the main game loop that continuously displays the current room's description while the game is running.

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

Create a variable called gameRunning and set it to true.

Write a while loop that continues as long as gameRunning is true. Inside the loop:

  • Print the description of the player's current room
  • Set gameRunning to false to exit the loop (for now, we'll add proper input handling in the next lesson)

Expected Output Format:

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 = "You find yourself in a dusty library filled with ancient books and scrolls."
}

-- Create the garden room
local gardenRoom = {
    name = "Secret Garden",
    description = "A beautiful garden with exotic flowers and a mysterious fountain."
}

-- Link the rooms
startingRoom.nextRoom = gardenRoom
gardenRoom.previousRoom = startingRoom

-- Create the player table
local player = {
    currentRoom = startingRoom
}

-- Print the player's current room name and description
print(player.currentRoom.name)
print(player.currentRoom.description)

All lessons in Logic & Flow