Page 1 of 1

Changing properties of dynamically created object

Posted: Sun Nov 09, 2014 1:40 pm
by Scotty
I'm struggling to figure out how I can change the properties of an object created via script at runtime. Where the ID of the object isn't known beforehand.

For example, spawning in a door, and then setting it's pullChain value to true.

Code: Select all

local ID_string = "door_" .. getUniqueID()
spawn("dungeon_door_iron", level_index, x, y, i, 0, ID_string)
[something goes here].door:setPullChain(true)

Re: Changing properties of dynamically created object

Posted: Sun Nov 09, 2014 2:00 pm
by Grimfan
If you simply want to spawn a door then:

Code: Select all

spawn("dungeon_door_iron", 1, 5, 23, 1, myDoor).door:setPullChain(true)
or something similar.

It depends on exactly what you want.

Re: Changing properties of dynamically created object

Posted: Sun Nov 09, 2014 2:44 pm
by Scotty
Very nice, works wonders! thanks

How about if I wanted to change multiple parameters, like spawn a monster and set its health as well as level? Still with a dynamically created string.

Re: Changing properties of dynamically created object

Posted: Mon Nov 10, 2014 5:37 am
by Scotty
Found the solution. findEntity(ID) converts a string into an object.

eg:

Code: Select all

local ID_string = "door_" .. getUniqueID()
spawn("dungeon_door_iron", level_index, x, y, i, 0, ID_string)
findEntity(ID_string).door:setPullChain(true)

Re: Changing properties of dynamically created object

Posted: Mon Nov 10, 2014 8:47 am
by Prozail
You can skip the id-parameter totally if you do

Code: Select all

local obj = spawn("dungeon_door_iron", level_index, x, y, i, 0)
obj.door:setPullChain(true)