1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Why isn't it working?

Discussion in 'Programming' started by seojaeoh, Jan 30, 2019.

  1. seojaeoh

    seojaeoh Member

    Joined:
    Jan 22, 2019
    Posts:
    31
    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.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,082
    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.
     
    seojaeoh likes this.
  3. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,217
    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 likes this.
  4. seojaeoh

    seojaeoh Member

    Joined:
    Jan 22, 2019
    Posts:
    31
    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: Jan 30, 2019
  5. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,082
    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).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice