• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Created Instance that can change creator's variables?

I am trying to make something where an instance is activated and it creates a different instance. and I need it so the created instance knows the creator. This way when you activate the newly created instance it changes a variable on the instance that created it. Any ideas? Thanks!
 

Roldy

Member
GML:
// If you don't need to do anything in the create event
var _newlyCreatedInstance = instance_create_layer(x, y, layer, oSomeObject);
_newlyCreatedInstance.myCreator = id;

// Or have a member function that performs what you need
_newlyCreatedInstance.SetMyCreator(id); // Set the creator and do stuff

// If you really want to be able to access the creator in the objects create event then consider

// Set a global
global.theCreator = id;

// Now oSomeObjects create event can access the global variable 'theCreator'
var _newlyCreatedInstance = instance_create_layer(x, y, layer, oSomeObject);

// Reset the global to undefined
global.theCreator = undefined;
Technically I think 'other' will work in this case to get the id of the creator from the create event. However, that is undocumented behavior.
 
Top