<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
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">/*<![CDATA[*/
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
/*]]>*/</style>
<script type="text/javascript">//<![CDATA[
gRootRelPath = "../..";
gCommonRootRelPath = "../..";
gTopicId = "9.1.0_2";
//]]></script>
<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>Runtime Functions</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 use of runtime functions"/>
<meta name="rh-index-keywords" content="Runtime Functions"/>
<meta name="search-keywords" content="functions,built-in functions"/>
</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="Runtime Functions">
<span>Runtime Functions</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>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>Runtime Functions</h1>
<p>The general definition of a function is something like this:</p>
<p><i>A function has an input and an output, and the output is related somehow to the input.</i></p>
<p>In GameMaker Studio 2 this translates into two different things, but they both work the same way:</p>
<ul class="colour">
<li><b>Runtime Functions</b> - A <i>runtime</i> function is one that is supplied as part of the <b>GameMaker Language</b> (GML). These are built in to the language and can be used to make things happen in your games and there are a great number of GML
runtime functions available to you, all of which are explained in the <a href="../GML_Reference/GML_Reference.htm">Language Reference</a> section of the manual.</li>
<li><b>Script Functions And Methods </b>- <em>Script </em>functions and <em>M</em><i>ethod Variables</i> are functions that you have created yourself using the basic building blocks of the <b>GameMaker Language</b> (GML), and these can include runtime
functions as part of their code.</li>
</ul>
<p>In both of the above cases a function has the form of a function <i>name</i>, followed by the <i>input <a class="tooltip" title="An argument (also known as a parameter) is a value that is passed into a function. For example, the GameMaker Language function 'sqr(num)' is a function that will give you the square of a number that you provide as the argument, eg: 'a = sqr(4);' Here the argument is 4, and the function will return 16, which is stored in the variable 'a'.">argument</a><span class="glossextra">s</span></i> between brackets <tt>()</tt> and separated
by commas (if the function has no input arguments then just brackets are used). This page concentrates on the <strong>runtime functions</strong> (ie: the ones that are built-in to GameMaker to form the GameMaker Language), but the general rules shown
below follow for all function types.</p>
<p>Here is an outline of the structure of a function:</p>
<p class="code"><function>(<arg0>, <arg1> ,... <argN>);</p>
<p>Some functions can return values and can be used in <a class="tooltip" title="An expression is a combination of one or more constants, variables, operators, and/or functions that are interpreted according to particular rules of precedence and association to return another value. A simple expression would be (5 + 5), which returns 10.">expression</a><span class="glossextra">s</span>, while others simply execute commands, as illustrated in the following two runtime function
examples:</p>
<p class="code">// Destroy the calling instance<br/> // This requires no arguments and returns nothing<br/> instance_destroy();
<br/>
<br/> // Get the distance from the current instance position to the mouse position<br/> // This takes four arguments and returns a real value<br/> dist = point_distance(x, y, mouse_x, mouse_y);</p>
<p>Sometimes the return value of a function may be a value that you want to use in an <a class="tooltip" title="An assignment is simply the term used when we set (assign) a value to a variable.">assignment</a>, but you should note that it is impossible to use any function <em>directly</em> as the left-hand
side of an assignment. For example, the following code to set the speed on an instance would give you an error:</p>
<p class="code">instance_nearest(x, y, obj).speed = 0;</p>
<p>The return value for the expression in that code example is an integer number (the unique ID value for the nearest instance) and so it must be enclosed in brackets to be used in this way and properly address the instance required (see <a href="Addressing_Variables_In_Other_Instances.htm">Addressing Variables In Other Instances</a> for more information). The above code would be correctly written as:</p>
<p class="code">(instance_nearest(x, y, obj)).speed = 0;<br/>
<br/> //or more correctly still<br/>
<br/> var inst = instance_nearest(x, y, obj);<br/> inst.speed = 0;</p>
<p>The <a href="../GML_Reference/GML_Reference.htm">Language Reference</a> section of the manual lists all of the runtime functions available to you and gives examples of how they can be used as well as other important information about what they may return
or any events that they may trigger, etc... For more information on user defined script functions and methods, see the section on <a href="Script_Functions.htm">Script Functions</a> and the section on <a href="Method_Variables.htm">Method Variables</a>.</p>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="GML_Overview.htm">GML Overview</a></div>
<div style="float:right">Next: <a href="Commenting_Code.htm">Commenting Code</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
<!-- KEYWORDS
Runtime Functions
-->
<!-- TAGS
runtime_functions
-->
</body></html>