entitiesAt()
entitiesAt()
I have written various pieces of script in Grimrock1 where I need to find an entity at a certain tile in the game; for example looking to see if there is a pit in front of the party. The 'for i in entitiesAt(level,x,y) do' script would return (I believe) the table value which could be used to see if a pit was there. I have noticed there is no entitiesAt function in Grimrock2. Can anyone tell me how this would be done in Grim2? Also, in viewing some of the tutorials for Grimrock2 I have notice that the iteration statements start like this: 'for v,i in ...'. Can anyone tell me what the v is for. I am trying to get a handle on this but the new script is a lot different than Grim1 and I am a bit confused. Any help would be appreciated. Thank you.
Re: entitiesAt()
entitiesAt is no longer a global function, it belongs to the Map class.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: entitiesAt()
Thank you.
Any help on the extra variable in the iteration loop (the '"'v'"' variable mentioned in the latter part of the post)?
P.S. I think I may be in the wrong part of the forum for this. Sorry!
Any help on the extra variable in the iteration loop (the '"'v'"' variable mentioned in the latter part of the post)?
P.S. I think I may be in the wrong part of the forum for this. Sorry!
Re: entitiesAt()
The construct is:
An iterator, like any other function in Lua, can have multiple return values. The iterators returned by pairs and ipairs are examples; they return both a key and the corresponding value in the table they're iterating over. So, for example, if you wanted to copy a table, you could use code like
A common convention is to use an underscore if you don't care about one or more of the return values, so you might see code like
but this is purely a convention and is not part of the language ('_' is a valid variable name like any other).
The iterator returned by Map:entitiesAt() and Map:allEntities() only returns one value, a GameObject. So blocks for those just look like
Code: Select all
for [variables] in [iterator] do [block] end
Code: Select all
for k,v in pairs(table1) do
table2[k] = v
end
Code: Select all
for _,dog in ipairs(dogs) do
pet(dog)
end
The iterator returned by Map:entitiesAt() and Map:allEntities() only returns one value, a GameObject. So blocks for those just look like
Code: Select all
for e in party.map:allEntities() do
print(e.id)
end
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: entitiesAt()
Thank you so much for the explanation. I was using iterators because I saw examples of such in the Grim 1 Scripting Reference but I didn't really understand them. Your explanation and code examples helped a lot.
I have other questions but will ask them in the Mod Creation forum as I think that is where I should be for this stuff. Please correct me if I am wrong.
Thanks again!
I have other questions but will ask them in the Mod Creation forum as I think that is where I should be for this stuff. Please correct me if I am wrong.
Thanks again!