[FUNCTION] Find entities with text and method filtering

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

Re: [FUNCTION] Find entities with text and method filtering

Post by Komag »

Okay, thanks, that does help it make much more sense.

And I tested and the ( ) are not necessary, but maybe Lark has a - perhaps wise/good - habit of including them even if they sometimes are redundant, because other times they are needed.

so now it basically boils down to:

Code: Select all

totalMonsters = 0
function countMonsters()
  for i=1,13 do
    for j in allEntities(i) do
      if j["setAIState"] ~= nil then
         j:setLevel(2)
         totalMonsters = totalMonsters + 1
      end
    end
  end
  print("there are "..totalMonsters.." monsters")
end
[/color][/b]

with the key to it all being the line:
if j["setAIState"] ~= nil then
which says "in the table of properties/info for entity j, if there is an item with the string "setAIState" then do something"

Is there a way to "print" all the properties of an entity, to print all its table values?
I tried:
for i in findEntity("spider_shock_1") do print(i) end and
for i in findEntity("spider_shock_1") do print(spider_shock_1) end and
for i in spider_shock_1 do print(i) end
but I got ":1: attempt to call a table value" error message or ":1: attempt to call a nil value"
Finished Dungeons - complete mods to play
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: [FUNCTION] Find entities with text and method filtering

Post by Batty »

So far, I've found that this:

Code: Select all

print(entity["name"])
gives the same result as this:

Code: Select all

print(entity.name)
I tried with interesting things like "model" but only got nil, would be cool to spit out all an objects info. but it may be inaccessible.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [FUNCTION] Find entities with text and method filtering

Post by petri »

In Lua entity["something"] is exactly the same as entity.something. The latter notation is just a shortcut and it exists in Lua because it would be very tedious to write the brackets and quotations all the time when accessing tables. The bracket notation is useful when e.g. the key between the brackets is not a string or contains spaces. For example,

entity["some property with spaces"] can't be written as "entity.some property with spaces" because that would be a syntax error.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: [FUNCTION] Find entities with text and method filtering

Post by Komag »

Ah, that helps make it more clear, thanks :)
Finished Dungeons - complete mods to play
Post Reply