Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 22, 2025
2 parents 832d495 + 4eeae55 commit 02f7f0b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,61 @@ <h2>Collision Event</h2>
other.hit = true;</p>
<h2 id="h">When &#39;other&#39; changes</h2>
<p>The page on <span class="inline2"><a data-xref="{title}" href="self.htm">self</a></span> contains a section on <a data-xref="{text}" href="self.htm#h">When &#39;self&#39; changes</a>.</p>
<p>This section will describe those cases in relation to how <span class="inline2">other</span> changes:</p>
<p>This section describes those cases in relation to how <span class="inline2">other</span> changes:</p>
<ul class="colour">
<li>Inside a <span class="inline3_func"><a data-xref="{title}" href="../Language_Features/with.htm">with</a></span> block, <span class="inline2">other</span> will be the instance or struct that called the <span class="inline2">with()</span> function</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = {<br />
    value : 99<br />
}<br />
<br />
with (_struct) <br />
{<br />
    show_debug_message(other.value); // Prints 40<br />
}
</p>
<ul class="colour">
<li>Using dot notation on a struct or instance (<span class="inline2">struct.variable</span>)</li>
<li>When calling a <a href="../Method_Variables.htm">method</a> that is bound to an instance or a struct, <span class="inline2">other</span> will be the instance or struct that called that method</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = instance_create_depth(0, 0, 0, Object2, {<br />
    value : 99,<br />
    func : function () {<br />
        return other.value;<br />
    }<br />
});<br />
<br />
var _func = _struct.func;<br />
<br />
show_message(_func()); // Prints 40
</p>
<ul class="colour">
<li>In the above case, calling <span class="inline2">_struct.func()</span> directly would return <span class="inline2">99</span>, as the scope first changes to <span class="inline2">_struct</span> due to dot notation, and then it changes again when the bound method is called, making the <span class="inline2">other</span> the previous scope at the moment the method is called, which is the struct (with <span class="inline2">value</span> set to <span class="inline2">99</span>)</li>
<li>When calling an unbound constructor function, <span class="inline2">other</span> will be the instance or struct that called that function. If the constructor is bound as a method, then <span class="inline2">other</span> will be the instance or struct to which the constructor method is bound.</li>
</ul>
<p class="code">value = 40;<br />
<br />
item = function () constructor {<br />
    value = 99;<br />
    <br />
    copied_value = other.value;<br />
}<br />
<br />
my_item = new item();<br />
show_debug_message(my_item.copied_value); // Prints 40
</p>
<ul class="colour">
<li>When stored as a reference through a struct literal, covered below under &quot;<strong>&#39;other&#39; as a reference</strong>&quot;.</li>
</ul>
<h3 id="legacy_other_behaviour">Legacy other Behaviour</h3>
<p>In previous versions of <span data-keyref="GameMaker Name">GameMaker</span> <span class="inline2">other</span> only changed in the following cases: </p>
<ul class="colour">
<li>As part of the <span class="inline2">with</span> statement.</li>
<li>When <span class="inline2">new</span> is called when a constructor is executed <span class="inline2">other</span> is set to the <span class="inline2">self</span> at the point that <span class="inline2">new</span> was called.</li>
<li>As part of the <span class="inline2">with</span> statement</li>
<li>When <span class="inline2">new</span> is called when a constructor is executed <span class="inline2">other</span> is set to the <span class="inline2">self</span> at the point that <span class="inline2">new</span> was called</li>
</ul>
<p>This behaviour can be enabled by the <a href="../../../Settings/Game_Options.htm#legacy_other_behaviour">Legacy Other Behaviour</a> game option.</p>
<h2>Struct Declaration</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,42 @@ <h1><span data-field="title" data-format="default">self</span></h1>
}</p>
<p>In this example you can see that we have a <i>local</i> variable called <span class="inline2">val</span> and we want it to set the <i>instance</i> variable with the same name in the newly created object instance. To identify the instance variable correctly and tell <span data-keyref="GameMaker Name">GameMaker</span> to set it in the instance calling the code block, we use the <span class="inline2">self</span> keyword.</p>
<p><span class="inline2">self</span> is used in the same way with <a href="../Structs.htm">structs</a> to reference member variables of the struct. It can also be used within constructor functions to reference the struct being generated from the constructor.</p>
<p class="note"><span data-conref="../../../assets/snippets/Tag_note.hts"> </span> Due to compatibility reasons, converting <span class="inline2">self</span> into a <a data-xref="{title}" href="../../GML_Reference/Strings/string.htm">string</a> will return -1.</p>
<h2 id="h">When &#39;self&#39; changes</h2>
<p>Within an event, the current <span class="inline2">self</span> will change in the following situations:</p>
<p>Within an event or script, the current <span class="inline2">self</span> will change in the following situations:</p>
<ul class="colour">
<li>Inside a <span class="inline3_func"><a data-xref="{title}" href="../Language_Features/with.htm">with</a></span> block, as shown above</li>
<li>When calling a <a href="../Method_Variables.htm">method</a> that is bound to an instance or a struct, the <span class="inline2">self</span> during the execution of that function will be the instance or struct to which the method is bound</li>
<li>Using dot notation on a struct or instance (<span class="inline2">struct.variable</span>)</li>
<li>When calling a <a href="../Method_Variables.htm">method</a> that is bound to an instance or a struct, the <span class="inline2">self</span> during the execution of that method will be the instance or struct to which the method is bound</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = instance_create_depth(0, 0, 0, Object2, {<br />
    value : 99,<br />
    func : function () {<br />
        return self.value;<br />
    }<br />
});<br />
<br />
var _func = _struct.func;<br />
<br />
show_message(_func()); // Prints 99
</p>
<ul class="colour">
<li>When calling a constructor function, <span class="inline2">self</span> will refer to the new struct that is being generated as a result of that function.</li>
</ul>
<p class="code">value = 40;<br />
<br />
item = function () constructor {<br />
    value = 99;<br />
    <br />
    copied_value = self.value;<br />
}<br />
<br />
my_item = new item();<br />
show_debug_message(my_item.copied_value); // Prints 99
</p>
<ul class="colour">
<li>When stored as a reference through a struct literal, covered below under &quot;<strong>&#39;self&#39; as a reference</strong>&quot;.</li>
</ul>
<p>In all of these cases, when <span class="inline2">self</span> changes to a new scope, <span class="inline2"><a href="other.htm">other</a></span> will be set to be the previous scope. The only exception is when a bound constructor method is called. This is described more in <a data-xref="{text}" href="other.htm#h">When &#39;other&#39; changes</a>.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>load_csv</title>
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css" />
Expand Down Expand Up @@ -34,5 +35,5 @@
<!-- TAGS
load_csv
-->

</body></html>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>handle_parse</title>
<meta name="generator" content="Adobe RoboHelp 2022"/>
<link rel="stylesheet" type="text/css" href="../../../assets/css/default.css"/>
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" type="text/css" href="../../../assets/css/default.css" />
<script src="../../../assets/scripts/main_script.js" type="module"></script>
<meta name="rh-authors" content=""/>
<meta name="topic-comment" content="Function reference page for handle_parse"/>
<meta name="rh-index-keywords" content="handle_parse"/>
<meta name="search-keywords" content="handle_parse"/>
<meta name="template" content="assets/masterpages/Manual_Keyword_Page.htt"/>
<meta name="rh-authors" content="" />
<meta name="topic-comment" content="Function reference page for handle_parse" />
<meta name="rh-index-keywords" content="handle_parse" />
<meta name="search-keywords" content="handle_parse" />
<meta name="template" content="assets/masterpages/Manual_Keyword_Page.htt" />
</head>
<body>
<h1><span data-field="title" data-format="default">handle_parse</span></h1>
Expand All @@ -22,9 +23,9 @@ <h4>Syntax:</h4>
<p class="code"><span data-field="title" data-format="default">handle_parse</span>(value_string);</p>
<table>
<colgroup>
<col/>
<col/>
<col/>
<col />
<col />
<col />
</colgroup>
<tbody>
<tr>
Expand All @@ -44,17 +45,17 @@ <h4>Returns:</h4>
<p class="code"><span data-keyref="Type_Handle"><a href="../../GML_Overview/Data_Types.htm" target="_blank">Handle</a></span> (or <span data-keyref="Type_Undefined"><a href="../../GML_Overview/Data_Types.htm" target="_blank">undefined</a></span> in case of an invalid string)</p>
<p> </p>
<h4>Example:</h4>
<p class="code">sprite = spr_player;<br/>
handle_as_string = string(sprite);<br/>
h = <span data-field="title" data-format="default">handle_parse</span>(handle_as_string);<br/>
<br/>
show_debug_message($&quot;{sprite} ({typeof(sprite)})&quot;);<br/>
show_debug_message($&quot;{handle_as_string} ({typeof(handle_as_string)})&quot;);<br/>
<p class="code">sprite = spr_player;<br />
handle_as_string = string(sprite);<br />
h = <span data-field="title" data-format="default">handle_parse</span>(handle_as_string);<br />
<br />
show_debug_message($&quot;{sprite} ({typeof(sprite)})&quot;);<br />
show_debug_message($&quot;{handle_as_string} ({typeof(handle_as_string)})&quot;);<br />
show_debug_message($&quot;{h} ({typeof(h)})&quot;);
</p>
<p>The code above converts the handle of a sprite named <span class="inline2">spr_player</span> to its string representation (<span class="inline2">handle_as_string</span>), and then back into a handle (<span class="inline2">h</span>). It then outputs each of the created instance variables in a debug message, along with its type. This prints the following:</p>
<p class="code_plain">ref sprite 0 (ref)<br/>
ref sprite (string)<br/>
<p class="code_plain">ref sprite 0 (ref)<br />
ref sprite (string)<br />
ref sprite 0 (ref)</p>
<p>You can see that the original reference is converted into a string, which is then parsed back as a reference, which can again be used in functions just like the original reference.</p>
<p>The values of the handle variables are implicitly converted to their string representation to display them.</p>
Expand All @@ -67,13 +68,13 @@ <h4>Example:</h4>
<div>Next: <a data-xref="{title}" href="variable_instance_exists.htm">variable_instance_exists</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2023 All Rights Reserved</span></h5>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
</div>
<!-- KEYWORDS
handle_parse
-->
<!-- TAGS
handle_parse
-->

</body></html>
</body>
</html>
Loading

0 comments on commit 02f7f0b

Please sign in to comment.