GML A function in event_inherited() to terminate the rest of children's code?

Discussion in 'Programming' started by Dawn, May 3, 2019.

  1. Dawn

    Dawn Member

    Joined:
    Sep 5, 2016
    Posts:
    58
    I want to add something like exit; in the parent's code so when the conditions are met children with event_inherited() won't run the rest of the code below it. Apparently exit; doesn't work as it only finishes what's inside the contents of event_inherited().

    I could just add if statements for each child or just add everything in the parent's code but it feels like it's not the right way to do it. Is there any way to do this?
     
  2. vdweller

    vdweller Member

    Joined:
    Jun 24, 2016
    Posts:
    140
    It's true, exit works only for the block of code you're currently in.

    I guess a global variable flag or something similar will do the trick, have the parent set it to 1 and have the children exit upon checking if it's 1 or something.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,371
    What about

    if <<condition>> return 0;

    ?
     
  4. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,477
    The events are secretly scripts, so it makes sense that "exit" only terminates the executing one.

    You could use a make a small wrapper like
    Code:
    /// event_inherited_ext()
    globalvar __exit; __exit = false;
    event_inherited();
    return __exit;
    Code:
    /// exit_ext()
    __exit = true;
    return true;
    and then
    Code:
    // parent event
    if (dead) return exit_ext();
    // ...
    Code:
    // child event
    if (event_inherited_ext()) exit;
    
     

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