Passing properties to spawned objects?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Passing properties to spawned objects?

Post by MadCatter »

When spawning an object from a script, is there a way to pass a property to the spawned object so that it links to the object that spawned it? (directly or indirectly)

Alternatively is there a way to find the ID of an object of a specific type at a given x/y location?
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Passing properties to spawned objects?

Post by Batty »

MadCatter wrote:Alternatively is there a way to find the ID of an object of a specific type at a given x/y location?
I have this script for finding IDs:

Code: Select all

function getID(self, name, coordX, coordY)
   for i in self.go.map:entitiesAt(coordX, coordY) do
      if i.name == name then
         print(name .. ' #1' .. ' = ' .. i.id)
         return i.id
      else
         print(name .. ' at ' .. coordX .. ', ' .. coordY .. ' not found')
      end
   end
end
Only finds the first instance of the object type you're looking for but it could be changed to find them all.

To call it from another script:

Code: Select all

global.script:getID('torch', 12, 18)
Post Reply