The Game Loop
Part of the Logic & Flow section of Coddy's Lua journey — lesson 27 of 54.
Challenge
EasyImplement 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
gameRunningtofalseto 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
1Advanced Table Iteration
Iterating with pairs()Iterating with ipairs()pairs() vs. ipairs()Recap - Character Sheet2More Table Library Functions
table.concat()table construction & unpack()table.sort()Custom Sorting with FunctionsRecap - High Score Board5Project: Text Adventure Engine
Project Setup: The RoomLinking Rooms