Why isn't it working?

seojaeoh

Member
Create blackbox, yellowbox, and greenbox in the object compartment, and greenbox creates blackbox in its place with Instance2 when the space key is pressed, blackbox disappears when it is created, and yellowbox is created 4 seconds later.

object 0 =>blackbox object 1 =>yellowbox

greenbox
1.keydown
instance_create_layer(x+0, y+0, "Instances2", object0);

blackbox
1.create:
var a;
a = 1;
instance_destroy();
if(a == 1)
{
alarm[0] = room_speed * 4 ;
}
2.alarm0:
instance_create_layer(x+0, y+0, "Instances2", object1);

yellowbox
nothing

(greenbox=>create black box =>black box destroy and create yellow box)

I'd appreciate it if you could let me know.
 

samspade

Member
Create blackbox, yellowbox, and greenbox in the object compartment, and greenbox creates blackbox in its place with Instance2 when the space key is pressed, blackbox disappears when it is created, and yellowbox is created 4 seconds later.

object 0 =>blackbox object 1 =>yellowbox

greenbox
1.keydown
instance_create_layer(x+0, y+0, "Instances2", object0);

blackbox
1.create:
var a;
a = 1;
instance_destroy();
if(a == 1)
{
alarm[0] = room_speed * 4 ;
}
2.alarm0:
instance_create_layer(x+0, y+0, "Instances2", object1);

yellowbox
nothing

(greenbox=>create black box =>black box destroy and create yellow box)

I'd appreciate it if you could let me know.
If you destroy an instance, its alarm can't keep counting down. So you create and destroy the black box before it can do anything.
 
What is going on in that code? I honestly don't understand it.

In black box, put this:
Create
Code:
alarm[0] = room_speed*4;
Alarm[0] Event
Code:
instance_create_layer(x,y,"Instances2",object1);
instance_destroy();
Also, why are you creating things at x+0,y+0? It's not going to break anything, but why put +0 when it literally does nothing? And why initialise a = 1, and then simply have if (a == 1) immediately after it? Again, there's -no- reason for that whatsoever, just have the alarm be set on it's own...
 

seojaeoh

Member
The destroy function destroys the next function as soon as it works. Thank you. But I heard that game maker is providing C language. I wonder if game maker has all C language functions or other forms.

I remember that the destroy function is the only function that destroys it. Is there a wait function instead of an alarm function? I heard it disappeared from game maker 2.

Thank you for being kind to people you don't know. everyone. :)
 
Last edited by a moderator:

samspade

Member
I remember that the destroy function is the only function that destroys it. Is there a wait function instead of an alarm function? I heard it disappeared from game maker 2.
I'm not entirely sure I understand. Are you asking whether or not there is a way to call a script locally in an object, destroy that object, and then have that script run later? If so, I don't think so.

Once you call instance destroy, the object will be destroyed. Any code in that object will cease to run. And effectively all code in GML runs through an object (there are things like room creation code, layer scripts and probably other things I haven't thought of, but they're all for very specific things). So, you can't tell an object to run code later and then destroy it (I believe at the end of the event where instance_destroy is called).
 
Top