hello.
So im making a crafting module which returns the result with the correct ingredients. The only problem is that how do i insert string values that doesn’t have indexes, like below here
-- a way to insert "Wood" without making it like this
-- what i dont want
local ingredients = {
[1] = "Wood",
[2] = "Stone",
[3] = "Wood",
}
-- what i want
local ingredients = {
"Wood"
"Stone"
"Wood"
}
you won’t probably understand, but i need it so i can’t make my life harder and just using table.find() if the recipe has a ingredient that matchs the original ingredient inserted.
So basically, do you know when you have a table and want to insert an apple and a banana.
Simply, you use table.insert()
and if you wanna review the table, you can print it out.
The only problem is that the items inside the table have numerical indexes, in which case i don’t want that.
local ingredients = {}
ingredients["Wood"] = true
print(ingredients["Wood"]) -- true (so you don't need to use table.find)
for ingredient, value in ingredients do
print(ingredient)
end
i didnt wanna use table.find() because i thought you can make indexes be set as a string, since i can’t do that, im just gonna find the other way to do it