• 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!

Spawning enemies with certain values?

G

GiraffeKey

Guest
How would I spawn an enemy from another object and then set a variable within that enemy? I want different enemies to have different values based on the objects they come from.
 

rIKmAN

Member
How would I spawn an enemy from another object and then set a variable within that enemy? I want different enemies to have different values based on the objects they come from.
Store the instance id of the created instance, then set the values you want depending on what object is spawning it, or you could use the with() function to do the same thing:
Code:
// use a var to get the instance id
var inst = instance_create_layer(x, y, layer_name, object_to_spawn)
inst.name = "Red";
inst.health = 1000;

// or use the with() function to do the same thing
var inst = instance_create_layer(x, y, layer_name, object_to_spawn)
with(inst)
{
     name = "Red";
     health = 1000;
}
Bare in mind that the values you are trying to set must exist in the object you are spawning - you can't change what doesn't exist.
 
Top