Recap - Item Properties
Part of the Fundamentals section of Coddy's Lua journey — lesson 70 of 90.
Challenge
EasyCreate a magical weapon management system that demonstrates all dictionary-style table operations. Start by creating a table named magicSword with the following initial key-value pairs: ["name"] should be assigned the string "Flamebrand", ["damage"] should be assigned the number 45, and ["rarity"] should be assigned the string "rare".
After creating the initial sword table, perform the following operations in sequence: First, modify the damage value to 55 to represent an upgrade. Next, add a new key-value pair ["enchantment"] with the value "fire" to show the sword's magical property. Finally, remove the rarity key by assigning nil to it since this information is no longer needed.
After completing all operations, print the sword's name, updated damage value, and enchantment type to verify the changes.
Try it yourself
-- Create the initial magicSword table
-- TODO: Write your code here
-- Print the final values
print(magicSword["name"])
print(magicSword["damage"])
print(magicSword["enchantment"])All 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 Chest2Variables 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 Username11Tables 2: Dictionary-Style
Key-Value PairsCreating Dictionary-Style TablAccessing - Bracket NotationAccessing with Dot NotationAdding and Modifying PairsRemoving Pairs with nilRecap - Item Properties3Operators 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