Changing properties of dynamically created object

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
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Changing properties of dynamically created object

Post 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)
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Changing properties of dynamically created object

Post 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.
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Re: Changing properties of dynamically created object

Post 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.
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Re: Changing properties of dynamically created object

Post 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)
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Changing properties of dynamically created object

Post 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)
Post Reply