The "Exit" Statement

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

The exit statement has the form:

exit;


"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:

{
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().


Back: GML Overview
Next: The "With" Construction
© Copyright YoYo Games Ltd. 2018 All Rights Reserved