I've just started working on my very first LoG custom maps, and I've hit a snag. I want to create an alcove that requires food to be placed on it before the party is able to progress through my map; however, I can't find a way to see if an item has a nutritionValue!
function itemPuzzle()
-- iterate through all contained items on alcove, checking for a matching name
for i in itemPuzzleAlcove:containedItems() do
if i.name == "pitroot_bread" then
-- do something like open a door or activate a counter
break
end
end
end
I want to do this (or something like it to detect food)
function itemPuzzle()
-- iterate through all contained items on alcove, checking for a matching name
for i in itemPuzzleAlcove:containedItems() do
if i.nutritionValue then
foodCounter:increment()
break
end
end
end
Well... since most of the definition values are nil for the check (except 'Class') I didn't see how to do it that way.
But the brute force method (your first example) does work; just add the full list.
function itemPuzzle()
-- iterate through all contained items on alcove, checking for a matching name
for i in itemPuzzleAlcove:containedItems() do
-- Supported foods (add any new food names to the list)
food = {
"pitroot_bread",
"rotten_pitroot_bread",
"rat_shank",
"boiled_beetle",
"baked_maggot",
"ice_lizard_steak",
"mole_jerky",
"blueberry_pie",
"grim_cap",
"herder_cap",
"snail_slice",
}
--Check if it's food
for x in pairs(food) do
if i.name == food[x] then
print("It's food!")
foodCounter:increment()
return
end
end
--Default case for when it's not food
print("It's not food!")
end
end
Thanks a bunch for the post! I was hoping to avoid the brute force approach as I was thinking about altering the puzzle to require that players place food items totaling some nutritional value. That way they can't just get rid of a couple of there "baked_maggot"'s; however, your solution will do exactly what I need.
indeed, the brute force approach is always effective, you should always weigh the downside of such an aspect, but in this case, the only sacrifice is blood, sweat and tears. so, iterate every item and DONE. Bravo! GREAT solution!
Currently conspiring with many modders on the "Legends of the Northern Realms"project.
"You have been captured by a psychopathic diety who needs a new plaything to torture." Hotel Hades