gm-docs-parser 1.0.0

A collection of typings for GameMaker Studio 2 manual pages
Documentation
<?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_1";
  
//]]></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>Basic Code Structure</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 basic code structure when using GML"/>
  <meta name="rh-index-keywords" content="Code Structure"/>
  <meta name="search-keywords" content="Code Structure,begin,end,statement"/>
</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="Basic Code Structure">
        <span>Basic Code Structure</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>Basic Code Structure</h1>
  <p>Code is written in <em>blocks</em> and a typical code block consists of a set of instructions, called <a class="tooltip" title="In programming, a statement is a single line of code written legally in a programming language that expresses an action to be carried out. A statement might have internal components of its own, including expressions, operators and functions. An example of a statement is A = B + 5. A GameMaker Studio 2 program is nothing but a sequence of one or more statements that together perform a task (like move the player). ">statement</a><span class="glossextra">s</span>, that are then interpreted by GameMaker Studio
    2 and used to make something happen within your game. That &quot;something&quot; can be as simple as adding 2 and 2 to get 4, or as complex as making an enemy run away when their health gets below a certain value. The actual structure of the program
    can vary greatly, depending on the functions it uses, but broken down to basics it just looks like this:</p>
  <p class="code">&lt;statement&gt;;<br/> &lt;statement&gt;;
    <br/> ...
  </p>
  <p>Statements should be separated with a &#39;;&#39; symbol to prevent errors with <a class="tooltip" title="A variable is a named value within a program which can be modified, stored and displayed whenever required. For example, if we have an integer variable with a name XYZ and it stores a value 10, we can then do things like A = XYZ + 10, which will set the value of the variable A to 20, since XYZ is 10 and we are adding 10 to it. You can also change variable values using operators, so doing XYZ = XYZ + 100 would modify the value of our XYZ variable to be equal to 110. Variables can also be used to store identifiers and references to different assets.">variable</a> declarations and to keep your code clean and tidy, and they can consist of variable declarations,
    <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> and calls to specific <strong>functions</strong>. You can also &quot;group&quot; statements together as a block using the curly brackets <tt>{}</tt> so that they run together, like in the following
      <a class="tooltip" title="Conditionals, conditional statements, and conditional expressions are features of general programming language, and they help the code make a choice whrere the result is either true or false. These can perform different actions depending on the need of the programmer, and multiple conditionals can be combined into a single condition, as long as the final value of the condition is either true or false. Examples of conditional statements are &#39;if&#39; and &#39;while&#39;.">conditional</a>  example:</p>
  <p class="code">if (&lt;conditional&gt;)<br/> {
    <br/> &lt;statement&gt;;
    <br/> &lt;statement&gt;;
    <br/> ...
    <br/> }
  </p>
  <p class="note"><b>NOTE</b>: The GameMaker Language will also accept <tt>begin</tt><span>  </span>and <tt>end</tt><span>  </span>instead of the curly brackets <tt>{}</tt>, although this is not typically the most common way to do it:</p>
  <p class="code">if (&lt;conditional&gt;)<br/> begin
    <br/> &lt;statement&gt;;
    <br/> &lt;statement&gt;;
    <br/> ...
    <br/> end
  </p>
  <p><br/> Here is a more visual representation of how a code block can look, this time created as a <b>script</b> in the GameMaker Studio 2 <a href="../../The_Asset_Editors/Scripts.htm">Script Editor</a>:</p>
  <p><img alt="Program Example" class="center" src="../../assets/Images/Scripting_Reference/GML/Overview/ProgramExample.png" style="cursor: nwse-resize;"/></p>
  <p>There are a number of different types of statements, expressions, conditionals and functions, all of which are discussed at length in subsequent sections of the manual.</p>
  <p class="note"><strong>NOTE</strong>: If you are new to programming then you may want to check out the <a href="../../Quick_Start_Guide/Quick_Start_Guide.htm">Quick Start Guide</a> before continuing.</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="Runtime_Functions.htm">Runtime Functions</a></div>
      </div>
    </div>
    <h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
  </div>
  <!-- KEYWORDS
Basic Code Structure
code structure
code block
statements
statement separator
begin
end
-->
  <!-- TAGS
structure
-->

</body></html>