Linking Rooms
Part of the Logic & Flow section of Coddy's Lua journey — lesson 25 of 54.
Challenge
EasyBuilding on your starting room, create a second room and link both rooms together through their exits tables.
You are provided with the startingRoom variable from the previous challenge (Ancient Library).
Create a new room called gardenRoom with the following details:
name: "Secret Garden"description: "A hidden garden with overgrown plants and a small fountain."exits: An empty table
Link the two rooms by adding exits to both:
- Add an exit from
startingRoomgoing"east"that leads togardenRoom - Add an exit from
gardenRoomgoing"west"that leads back tostartingRoom
Print the name of the starting room, then print the name of the room you reach by going east from the starting room, then print the name of the room you reach by going west from that room.
Expected Output Format:
Ancient Library
Secret Garden
Ancient LibraryTry it yourself
local startingRoom = {
name = "Ancient Library",
description = "You find yourself in a dusty library filled with ancient books and scrolls.",
exits = {}
}
print(startingRoom.name)
print(startingRoom.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