Detect that item is food?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
jsi7iv
Posts: 3
Joined: Mon Jul 01, 2013 10:27 pm

Detect that item is food?

Post by jsi7iv »

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!

I know I can do this

Code: Select all

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)

Code: Select all

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

Any Ideas?

Thanks in advance!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Detect that item is food?

Post by Isaac »

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.

Code: Select all

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
jsi7iv
Posts: 3
Joined: Mon Jul 01, 2013 10:27 pm

Re: Detect that item is food?

Post by jsi7iv »

Isaac,

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.

Thanks :)
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Detect that item is food?

Post by msyblade »

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
Post Reply