<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
</script>
<style type="text/css">
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
</style>
<script type="text/javascript">
gRootRelPath = "../../..";
gCommonRootRelPath = "../../..";
gTopicId = "9.1.2.0_9";
<script type="text/javascript" src="../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>exit</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Page outlining the exit function"/>
<meta name="rh-index-keywords" content="exit"/>
<meta name="search-keywords" content="exit"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="exit">
<span>exit</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<h1>exit</h1>
<p>The <tt>exit</tt> statement has the following syntax:</p>
<p>exit;</p>
<p><tt>exit</tt> simply ends the execution of the current <a href="../Script_Functions.htm">script function</a>, <a href="../Method_Variables.htm">method</a>, or <a href="../../../The_Asset_Editors/Object_Properties/Object_Events.htm">event</a>. Note there
is a slight difference in use here depending on the scope:</p>
<ul class="colour">
<li>if you use <tt>exit</tt> in a scrpt function or method it will simply exit the function and return to the code that called the it</li>
<li>if you use <tt>exit</tt> in a code block from within an object, it will exit <i>the entire event</i> even if there are various separate code blocks after <span class="inline">exit</span> has been called.</li>
</ul>
<p>Typically <tt>exit</tt> 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:</p>
<p class="code">if (!visible)<br/> {
<br/> exit;
<br/> }
<br/> while (place_meeting(x, y))<br/> {
<br/> x -= lengthdir_x(1, direction - 180);<br/> y -= lengthdir_y(1, direction - 180);<br/> }
</p>
<p>The above code checks a variable and if it resolves to <tt>true</tt>, then it exits the code block, otherwise it goes ahead and runs the rest of the code.</p>
<p class="note"><b>NOTE</b>: It does not end the execution of the game. For that you need to use the function <span style="font-size:1px;"><a href="../../GML_Reference/General_Game_Control/game_end.htm"><tt style="font-size: 14px">game_end()</tt></a></span>.</p>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../Language_Features.htm">Language Features</a></div>
<div style="float:right">Next: <a href="with.htm">with</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>