Menu
Coddy logo textTech

Adding a Potion

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

challenge icon

Challenge

Easy

Building on your empty inventory table from the previous lesson, create your first magical potion and add it to the shop's inventory. Create a dictionary-style table named healthPotion with the following properties:

  • name with the value "Health Potion"
  • price with the value 15
  • stock with the value 8

After creating the potion table, use table.insert() to add the healthPotion table as the first element in your inventory table. This creates a nested table structure where your inventory contains potion tables.

Finally, print the length of the inventory table to confirm that one potion has been successfully added to your shop.

Try it yourself

-- TODO: Write your code here
inventory = {}

-- Print the length of the inventory table
print(#inventory)

All lessons in Fundamentals