Page 1 of 1

what's wrong with my coding here? containedItems()

Posted: Tue Jul 16, 2013 8:38 pm
by Komag
Here's the example code that's still throwing off the nil value error message:

Code: Select all

for i in entitiesAt(party.level,party.x,party.y) do 
  if i:containedItems()~=nil then 
    for j in i:containedItems() do 
      print(j.name) 
    end 
  end 
end
but it's still saying "attempt to call method 'containedItems' (a nil value)" and stops looking for more items after that

It's been a while since I did any lua, so it's probably something obvious I've forgotten.

Re: what's wrong with my coding here? containedItems()

Posted: Tue Jul 16, 2013 8:59 pm
by JohnWordsworth
Where you have 'if i:containedItems()~=nil then', you are calling the method containedItems and then checking whether the result is nil. Not all entities will have that method (as some won't be items). Instead, you might want to try:

if i.containedItems~=nil then ...

(Notice the change from i: to i. - I forgot that initially!)

Re: what's wrong with my coding here? containedItems()

Posted: Tue Jul 16, 2013 11:42 pm
by Komag
thanks, I'll try that :)