Menu
Coddy logo textTech

Recap - Manage Party Members

Part of the Fundamentals section of Coddy's Lua journey. Lesson 63 of 90.

challenge icon

Challenge

Easy

Create an adventuring party management system that demonstrates all the core list-style table operations. Start by creating a table named adventurers containing exactly three string values: "Gandalf", "Legolas", and "Gimli". After creating the table, perform the following operations in sequence:

First, use the length operator # to print the current number of party members. Next, use table.insert() to add "Aragorn" as a new member to the party. Then, use table.remove() to remove the first member from the party. To remove an element at a specific position, pass the index as a second argument: table.remove(adventurers, 1) removes the element at index 1 (which is "Gandalf") and automatically shifts the remaining members down. Finally, print the length of the party again to show the final count.

Try it yourself

-- Create the adventurers table with the initial members
local adventurers = {"Gandalf", "Legolas", "Gimli"}

-- TODO: Write your code here
-- 1. Print the current number of party members using the length operator
-- 2. Add "Aragorn" to the party using table.insert()
-- 3. Remove the first member using table.remove()
-- 4. Print the final number of party members

All lessons in Fundamentals

Practice on your own: Online Lua compiler