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

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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.
Finished Dungeons - complete mods to play
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

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

Post 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!)
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post by Komag »

thanks, I'll try that :)
Finished Dungeons - complete mods to play
Post Reply