Page 4 of 8

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 2:54 am
by vorebane
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

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:07 am
by Komag
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

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 9:11 am
by Crisim
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

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 2:07 pm
by Komag
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"

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 2:15 pm
by petri
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.

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:16 pm
by akroma222
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!!

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:18 pm
by Komag
probably just set up each alcove individually, then link to a counter set to three and then link the counter to the door(s)

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:24 pm
by Komag
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

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:31 pm
by petri
The names should be quoted in the list..

Re: How to check which item is in alcove?

Posted: Fri Oct 05, 2012 4:33 pm
by akroma222
Thanks Komag, I will repost when I have some results! :-)