How to check which item is in alcove?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
vorebane
Posts: 41
Joined: Wed Oct 03, 2012 4:31 am

Re: How to check which item is in alcove?

Post by vorebane » Fri Oct 05, 2012 2:54 am

It should work the same way you figure out if a specific item is in there via the for loop. Instead of i.name, i.meleeWeapon, or i.accuracy should return a value you can test against what it should be. As for my brute force solution, ta da! Be careful, sharp edges, ugly code, not actually tested just yet, etc.

edit: it doesn't actually work, even with a seperate button. Mysterious!

Code: Select all

function istheitemsthere()
if place:getItemCount() == 3 then
  for i in place:containedItems() do
    if i.name == "item1" then
      for i in place:containedItems() do
        if i.name == "item2" then
          for i in place:containedItems() do
            if i.name == "item3" then
--you made it!  the three things are here, do what happens!
            end
          end
        end
      end
    end
  end
end
end

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag » Fri Oct 05, 2012 4:07 am

I can't test it now, but I seem to remember someone else having a problem with too many i's, have to use other letters or whatever, only once each
Finished Dungeons - complete mods to play

User avatar
Crisim
Posts: 16
Joined: Wed Aug 29, 2012 2:28 pm

Re: How to check which item is in alcove?

Post by Crisim » Fri Oct 05, 2012 9:11 am

I think you could use the code from petri above
petri wrote:

Code: Select all

-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function containsItem(entity, item)
	for i in entity:containedItems() do
		if i.name == item then
			return true
		end
	end
	-- if we get here the item was not found
	return false
end
and write

Code: Select all

function istheitemsthere()
  if containsItem(place, "item1") and containsItem(place, "item2")  and  containsItem(place, "item3") then
    --you made it!  the three things are here, do what happens!
  end
end

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag » Fri Oct 05, 2012 2:07 pm

I'm somewhat at a loss - I'm getting nowhere trying to use variations of i.attackMethod, i.attackPower, i.reachWeapon, etc

example:

Code: Select all

function weaponCheck()
  if weaponalcove:getItemCount() == 0
  then
    weapondoor:close()
  else
    for i in weaponalcove:containedItems() do
      if i.attackMethod == meleeAttack
      then
        weapondoor:open()
        return
      end
    end
    weapondoor:close()
  end
end
this allows ANY object to open the door, even a necklace!
if I put it in quotes like "meleeAttack", then NOTHING will open the door, even obvious melee weapons.

everything else I've tried either doesn't work at all or gives an error. example:

Code: Select all

function weaponCheck()
  if weaponalcove:getItemCount() == 0
  then
    weapondoor:close()
  else
    for i in weaponalcove:containedItems() do
      if i.attackPower > 0
      then
        weapondoor:open()
        return
      end
    end
    weapondoor:close()
  end
end
as soon as a place a dagger there it crashes to editor with "attempt to compare number with nil"
Finished Dungeons - complete mods to play

User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: How to check which item is in alcove?

Post by petri » Fri Oct 05, 2012 2:15 pm

Unfortunately there is no such thing as "i.attackMethod" (or i.attackPower, i.reachWeapon, etc.). Only those properties and methods that are described in the script interface can be used. These would be good additions so I'll add them to the big list of wishes for next version.

I'm afraid the only way to implement the puzzle is to store a list of weapon names in a table and check each item in the alcove against the list.

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: How to check which item is in alcove?

Post by akroma222 » Fri Oct 05, 2012 4:16 pm

Hey folks!

I realize that the thread has turned to 'how to get the right weapon in the alcove' but my question is definitely for the this thread.
I used the coding for 'leave a blue gem in the alcove to open door/close door when removed' - THANK YOU!!

I have a trickier question (so I believe)-
I have three alcoves, each requiring a different colored gem, in order to open 1 or 2 secret doors.

Got no idea on this one lol... any help or direction would be muchly muchly appreciated!!

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag » Fri Oct 05, 2012 4:18 pm

probably just set up each alcove individually, then link to a counter set to three and then link the counter to the door(s)
Finished Dungeons - complete mods to play

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How to check which item is in alcove?

Post by Komag » Fri Oct 05, 2012 4:24 pm

Okay, I'm working on setting up the weapon table, but I'm not sure how to get it right. Here's my attempt that has no effect:

Code: Select all

function weaponCheck()
  local weaponlist = { dagger, legionary_spear, arrow }
  if weaponalcove:getItemCount() == 0
  then
    weapondoor:close()
  else
    for j=1,3 do
      for i in weaponalcove:containedItems() do
        if i.name == "weaponlist[j]"
        then
          weapondoor:open()
          return
        end
      end
    end
    weapondoor:close()
  end
end
Finished Dungeons - complete mods to play

User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: How to check which item is in alcove?

Post by petri » Fri Oct 05, 2012 4:31 pm

The names should be quoted in the list..

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: How to check which item is in alcove?

Post by akroma222 » Fri Oct 05, 2012 4:33 pm

Thanks Komag, I will repost when I have some results! :-)

Post Reply