Page 1 of 1

Passing properties to spawned objects?

Posted: Sun Nov 30, 2014 6:12 pm
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?

Re: Passing properties to spawned objects?

Posted: Sun Nov 30, 2014 6:44 pm
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)