Recap - Manage Party Members
Part of the Fundamentals section of Coddy's Lua journey — lesson 63 of 90.
Challenge
EasyCreate 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 membersAll lessons in Fundamentals
4Operators 2 Relational & Logic
Equality OperatorsRelational OperatorsThe 'and' OperatorThe 'or' OperatorThe 'not' OperatorShort-Circuit EvaluationTruthy and Falsy ValuesRecap - Simple Logic7Basic Conditional Logic
The if-then StatementThe if-then-else StatementThe elseif StatementRecap - Treasure Chest10Tables Part 1: List-Style
What is a Table?Creating a TableAccessing Elements by IndexModifying Elements by IndexThe Length Operator '#'table.insert()table.remove()Recap - Manage Party Members2Variables and Data Types
What is a Variable?NumbersStringsBooleansThe Value 'nil'The type() FunctionNaming ConventionsRecap - Character Profile5Basic Output
Printing LiteralsPrinting VariablesPrinting Multiple ValuesCombining Strings & VariablesThe tostring() FunctionInputCastRecap - Status ReportRecap - Till 1208String Manipulation Basics
string.len()string.upper & string.lowerstring.sub()string.rep()string.find()Recap - Format Username3Operators 1 Arithmetic & Conc
Arithmetic OperatorsModulo OperatorExponentiation OperatorString ConcatenationOperator PrecedenceRecap - Simple Calculations6Project: Character Stats Disp
Welcome MessageDeclare Character Stats9Functions Basics
Declaring a FunctionCalling a FunctionFunctions with ParametersFunctions with Multiple ParamsThe 'return' StatementRecap - Area Calculator