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

SOLVED Making instances do stuff in order, when created at the same time

B

Bucka-Zorkh

Guest
Hi,

I'm trying to make four instances of the same object do something in a certain order. But since the objects are created at the same time (when the room starts) I can't, that I know of, assign them a unique variable value that I can then use to say in which order the instances should execute their code (with a For loop).

I could probably use the Instance creation code, in the room editor, but if possible, I would like to assign them the value from the object or a control object.

Maybe I can use the Instances ID's, but I don't know much about that.


I have obj_BluePrint and four instances of this object is created when the room starts.

I want the First BluePrint to get a value from a ds_list. Then I remove that value from the list, so that the next BluePrint can't get the same value.



If could just set the variable "order" to 0, 1, 2 and 3, I know how to do everything else.
 

woods

Member
shot in the dark..

hold a counter in a control object of some sort
have the first of the four instances create the second, then the second will create the third, then the third will create the fourth..
 

chamaeleon

Member
Have a control instance whose purpose it is to, using with() in the right order, either call a function that does the required job or invokes a user event?

Edit: My response was more to step based iteration in a specific order. Not really relevant for instance creation initialization.
 

Nidoking

Member
If the order in which the instances execute something matters, then I think your design is inherently flawed. Rather than putting this in the obj_BluePrint, why not assign the variables wherever the instances are created? I don't think you'll be able to do that easily in the Room Editor, but if you've got a controller creating them, you'd do it there.
 
B

Bucka-Zorkh

Guest
hold a counter in a control object of some sort
have the first of the four instances create the second, then the second will create the third, then the third will create the fourth..
But how would I tell which one is the first?

If the order in which the instances execute something matters, then I think your design is inherently flawed. Rather than putting this in the obj_BluePrint, why not assign the variables wherever the instances are created? I don't think you'll be able to do that easily in the Room Editor, but if you've got a controller creating them, you'd do it there.
Yes, that's the problem: they are all created at the same time, not from another object - they are already placed in the room from the start.
I wanted to keep it that way, so I could design the different rooms with BluePrints and not have to program a controller for every room to create an instance of BluePrint in very specifik places.


So my question is "is it possible to give four instances of the same object a unique value in a variable, if they are created at the same time?"
 

Nidoking

Member
You can still use a controller to do that, but it will need to operate after the instances are created, such as in the Room Start event. That's really going to be your easiest way to do it.
 

chamaeleon

Member
If you have placed 4 instances in a room editor, what prevents you from using the instance editor to set a variable in the range 0-3 for your four instances? You may need to provide more context what you want to do. You talk about assigning a variable a value, but you also talk about executing code in some order. What needs to happen, and how often? Is it only initialization, or is it something you need to happen every step?
 
B

Bucka-Zorkh

Guest
Sorry guys, I'll try to explain better (and thanks for the help!)

I have 4 instances of obj_BluePrint in a room - they are created at the same time
I want to give them a number for later reference: 0-3 in let's say var order

If I created the instances with a control object, I would assign them the order value in the loop that created them.
If I assign them the value during their own create event, they will of course get the same value.

You can still use a controller to do that, but it will need to operate after the instances are created, such as in the Room Start event. That's really going to be your easiest way to do it.
Ok, but how would I "point" towards on of the instances, and make that instance var order = 0, and the next one = 1? Do I have to use instance ID for that?

If you have placed 4 instances in a room editor, what prevents you from using the instance editor to set a variable in the range 0-3 for your four instances? You may need to provide more context what you want to do. You talk about assigning a variable a value, but you also talk about executing code in some order. What needs to happen, and how often? Is it only initialization, or is it something you need to happen every step?
Nothing really prevents me from doing it this way, but I wanted to understand if there is another way to do it, because I will have many rooms with this BluePrint, and in each individual room there has to be an order. I really just wanted to be able to skip the step where I manually write the variable for each instance.
 

chamaeleon

Member
Use the Instance Creation Order list in the room editor to order them in the manner you wish them to be created?
 

sylvain_l

Member
Ok, but how would I "point" towards on of the instances, and make that instance var order = 0, and the next one = 1? Do I have to use instance ID for that?
in the room start envent something like
GML:
var i=0;
with( obj_BluePrint)
{
    order = i;
    i++;
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Use the Object Variables option in the object editor. Give them a "my_num" value or something, then in the room editor you can set this value. Just double click on the instance in the room, then open the Object Variables window, and set the value to what you need. This can then be checked in the create event of the instance since it is set before that event runs. :) I use this kind of thing all the time... it's incredibly handy (for things like telling a button what door to open, or a key what chest to unlock, etc...).

 
Hacky solution here which I'm not really a fan of, but if you create them at room start, why not create them in the editor, and use the room creation order tab to sort them out instead? If all you have is there, and you won't need to add/remove/change to the order of things later on, I don't see why it wouldn't work, and it could be done in under one minute.
 
B

Bucka-Zorkh

Guest
Thanks a lot for the help everyone!
I will try this all out!
 
Top