<?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.0_3";
<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>Commenting Code</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 comments in code"/>
<meta name="rh-index-keywords" content="Commenting Code"/>
<meta name="search-keywords" content="Comments,region,endregion,regions"/>
</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="Commenting Code">
<span>Commenting Code</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>Commenting Code</h1>
<p>When working in collaboration with other people, when dealing with a large project, or even just for your own reference and debugging, leaving comments in your event code and scripts is very important. In GameMaker Studio 2 you have various mechanisms
to help you leave notes and comments about code sections and even whole blocks of code that can be seen in the event list of the object that you are currently editing. In this way you can leave notes to yourself and to your colleagues, or to explain
a particularly tricky piece of code, or even just leave a reminder about what something does, or what you want something to do in the future.</p>
<p>To leave a simple one-line comment, the first thing you can do is use <span class="inline"><b><tt>//</tt></b></span> before the text. For example:</p>
<p class="code">//initialize variables<br/> sr = 10;<br/> hp = 100;</p>
<p>You may also leave multi-line comments, to give credit, to omit a complete section of code for debugging, or even to leave notes about how you want to change the code in the future. For that you can use <b><tt>/* ... */</tt></b> like this:</p>
<p class="code">/*<br/> Setup GIF Variables to initial values (these can be edited so you don't need to use the setter functions all the time if you are always using the same values)<br/>
<br/> IMPORTANT! Please see the individual "set" scripts for more extensive information about each of the different variables.<br/> */
<br/>
<br/> frame_num = 30;<br/> frame_steps = 5;<br/> frame_width = 256;<br/> frame_height = 256;<br/> frame_quality = gifcam_quality_high;</p>
<p>Apart from comments you can also use special <tt>#region</tt> tags to mark a section of code for <b>Code Folding</b>, and each region can contain a comment. How this works is that you add a <tt>#region</tt> tag - along with any comment text - to the
top of a section of code and then add a corresponding <tt>#endregion</tt> tag to the bottom of the section and then you can "fold" the code, ie: hide it away so you can cut down on the number of lines of code visible in the editor at any
one time:</p>
<p><img alt="Code Regions example" class="center" src="../../assets/Images/Scripting_Reference/GML/Overview/editor_scripts_coderegion.gif"/>The actual code looks something like this:</p>
<p class="code">#region This is an example region<br/>
<br/> width = sprite_get_width(sprite);<br/> height = sprite_get_height(sprite);<br/> xoff = sprite_get_xoffset(sprite);<br/> yoff = sprite_get_yoffset(sprite);<br/>
<br/> #endregion Further comment here if required</p>
<p>Finally, it's worth mentioning that when working with events in the <a href="../../The_Asset_Editors/Objects.htm">Object Editor</a>, you can use a special "<span class="inline">description</span>" comment at the start of the event to say
what the general contents of the event are, and this will show in the Object Editor events window. This should go on the very first line of the code editor, and is formatted as follows:</p>
<p class="code">/// @description <This Is An Event Description></p>
<p>This will now be shown in the event window, eg:</p>
<p><img alt="Event Title Comment" class="center" src="../../assets/Images/Scripting_Reference/GML/Overview/Event_Comment.png"/>Note that you can define a default comment to be created for all events from the <a href="../../Setting_Up_And_Version_Information/IDE_Preferences/Object_Editor_Preferences.htm">Object Editor Preferences</a>.</p>
<p>Finally, if you are writing <a href="Script_Functions.htm">script functions</a> and want to have some control over how they are treated by the IDE (ie: have auto-complete or show the script parameters) then you should be writing your comments using
JSDoc notation as explained <a href="../../The_Asset_Editors/Code_Editor_Properties/JSDoc_Script_Comments.htm">here</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="Variables_And_Variable_Scope.htm">Variables And Variable Scope</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>