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

Legacy GM Refering to an object depending on the number on the end of the name of the object? (SOLVED)

Fixer90

Member
I'm making a script function that will create an object (at coordinates 0, 0) called "obj_event_0", but I also have "obj_event_1" and "obj_event_2" and so on. I want to be able to input only a number in my function's argument whenever I use it; a number corresponding to the number at the end of the event object. Is this possible?

EDIT: I'm experimenting on this. Would something like this work?:
Code:
instance_create(0, 0, real("obj_event_" + string(argument0)));
 
Last edited:

Rob

Member
I think you'd find it easier to have 1 event object and then have a variable that tracks the different events. You can then just change that variable.

It IS possible to do it the way you want to but it would take you a lot longer.
 

Fixer90

Member
I think you'd find it easier to have 1 event object and then have a variable that tracks the different events. You can then just change that variable.

It IS possible to do it the way you want to but it would take you a lot longer.
You mean like having one persistent object, that has each event object listed in an array, and calls upon them based on that? I could do that, but if it is possible to do it the way I want, I want to know how. Do you know?
 

Rob

Member
I don't like any of the ways that come to mind but you could do this:

Code:
//scr_main(number)
number = argument0;

if (number == 0) instance_create(x,y,obj_event0);
if (number == 1) instance_create(x,y,obj_event1);
On my previous post i meant that you should just have 1 object that has all the same code of the different event objects.

You could then do something like this:

Code:
event = instance_create(x,y,obj_event);
event.number = //whatever you want for this code
then in obj_event, you have this in the step event

Code:
//Step event

if (number == 0){

}else{
   if (number == 1){

   }
}

etc
 
Last edited:

Fixer90

Member
I don't like any of the ways that come to mind but you could do this:

Code:
//scr_main(number)
number = argument0;

if (number == 0) instance_create(x,y,obj_event0);
if (number == 1) instance_create(x,y,obj_event1);
The problem with that is that I need to be able to have as many as thousands of event objects.
 

Rob

Member
If you want all those event objects to be different then you're gonna have to type / copy&paste all those lines, which is why I suggest ONE event object, with all the different bits of event code inside it.

I updated my previous post to explain this, so you might not have seen what I wrote.
 
Top