Player State
Part of the Logic & Flow section of Coddy's Lua journey — lesson 26 of 54.
Challenge
EasyBuilding 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 thestartingRoom
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
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