Here is an example of LUA code that includes functions to store and retrieve categories, titles, and their respective values:
lua
-- Initialize an empty table to store the data
local data = {}
-- Function to add a new category
function addCategory(category)
-- Check if the category already exists
if data[category] then
print("Category already exists!")
else
-- Create a new table to store the titles and their values
data[category] = {}
print("Category added successfully!")
end
end
-- Function to add a new title and its values to a category
function addTitle(category, title, value1, value2, value3)
-- Check if the category exists
if data[category] then
-- Check if the title already exists in the category
if data[category][title] then
print("Title already exists in this category!")
else
-- Create a new table to store the values
data[category][title] = {value1, value2, value3}
print("Title added successfully!")
end
else
print("Category does not exist!")
end
end
-- Function to retrieve the values of a title in a category
function getValues(category, title)
-- Check if the category exists
if data[category] then
-- Check if the title exists in the category
if data[category][title] then
return data[category][title][1], data[category][title][2], data[category][title][3]
else
print("Title does not exist in this category!")
end
else
print("Category does not exist!")
end
end
-- Example usage
addCategory("Books")
addTitle("Books", "Harry Potter", 5, 10, 15)
-- Retrieve values of a title
local value1, value2, value3 = getValues("Books", "Harry Potter")
print("Values:", value1, value2, value3)
In this code, the data table is used to store the categories, titles, and their respective values. The addCategory function adds a new category to the data table. The addTitle function adds a new title and its values to a specific category. The getValues function retrieves the values of a title in a specific category.