The "Exit" Statement

Here we explain how to use the "exit" statement.

The exit statement has the form:

GML Code Example


"Exit" simply ends the execution of the current script or event. Note the difference here, as if you use exit in a script is will simply exit the script and return to the code that called the script, however if you use this event in a code block from within an object, it will exit the entire event even if there are various separate code blocks after the function has been called. Typically it is used to avoid an instance running a specific block of code in, for example a collision event. The code below gives a simple example of this:

GML Code Example

 if invisible exit;
 while (place_meeting(x, y))
    x -= lengthdir_x(1, direction - 180);
    y -= lengthdir_y(1, direction - 180);

The above code checks a variable and if it resolves to true, then it exists the code block, otherwise it goes ahead and runs the rest of the code.

Note: It does not end the execution of the game. For that you need to use game_end().

No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here