• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

How can you make an object with independent variables?


The title is confusing but I don't know how else to describe it.
I will try my best to simplify with this analogy

For example, I have a bullet. I want to make it go a range of different speeds without having to make each speed its own object.

My plan is to find a way to change the variable when it created but I don't know how to do it.

Using a global variable like this will work:

Summoner's step event
global.speed = 0
global.speed = 3
global.speed = 5
Bullet's creation event
placeholder_speed = global.speed
Bullet's step event
x += placeholder_speed
but this feels like a very roundabout way of doing it. Is there a simpler or cleaner way of doing this?
I'd look into the random_range and choose functions. For example:
Bullet's Create Event:

placeholder_speed = choose(0,3,5);

//NOTE: If placeholder_speed is set to zero, your bullet will not actually go anywhere.


The instance_create functions return an id that you can store and use to refer to an instance and it's variables directly.

var b1 = instance_create_layer(x, y, "layer", bullet);
b1.speed_variable = 3;
Last edited:


When you create the instance, attach the variables to that particular instance.

var bullet = instance_create_layer(x, y, "Instances", bullet);
bullet.spd = 3;
This creates the bullet and assigns its instance id to the variable "bullet", then assigns the value "3" to the variable "spd" for this particular instance of a bullet object.