Menu
Coddy logo textTech

Recap - Item Properties

Part of the Fundamentals section of Coddy's Lua journey — lesson 70 of 90.

challenge icon

Challenge

Easy

Create 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