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 Aug 23, 2024
2 parents 15d9390 + e89ce30 commit 80ed197
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 11 deletions.
65 changes: 65 additions & 0 deletions Manual/contents/Additional_Information/Objects_vs_Instances.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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" />
<title>Objects vs. Instances</title>
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../assets/css/default.css" type="text/css" />
<script src="../assets/scripts/main_script.js" type="module"></script>
<meta name="rh-authors" content="" />
<meta name="topic-comment" content="" />
<meta name="rh-index-keywords" content="Objects_vs_Instances" />
<meta name="search-keywords" content="Objects_vs_Instances" />
<meta name="template" content="assets/masterpages/Manual_Page.htt" />
</head>
<body>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1><span data-field="title" data-format="default">Objects vs. Instances</span></h1>
<p>One of the first assets you work with in <span data-keyref="GameMaker Name">GameMaker</span> are <a href="../The_Asset_Editors/Objects.htm">Objects</a>. An object lets you define how something in your game behaves (e.g. a player or enemy).</p>
<p>Then in <a data-xref="{title}" href="../The_Asset_Editors/Rooms.htm">The Room Editor</a>, you drag an object into a room, so it actually appears in-game. That&#39;s where an <strong>object</strong> stops and an <strong>instance</strong> begins.</p>
<p>An instance is created from an object and you can have multiple instances of an object in a room. Each instance can go its own way and you can modify each instance of an object separately.</p>
<h2>Difference At Runtime</h2>
<p>Understanding the difference between objects and instances is important as they both exist as resources at runtime.</p>
<p><a href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/Instances.htm">Instances</a> are prominent at runtime as they are the primary drivers of your game: they are the ones executing your code and interacting with other instances to form gameplay. <a href="../GameMaker_Language/GML_Reference/Asset_Management/Objects/Objects.htm">Objects</a> on the other hand continue to exist as <strong></strong><em>background resources</em>, and they can be modified and used to create new instances.</p>
<p>There are functions and language features that operate on both objects (the background resource) and instances (its actual presence in the room), and as such it becomes important to understand the differences between using either resource in such functions.</p>
<h3>Accessing Variables</h3>
<p>You can access variables from an instance via dot notation, i.e. <span class="inline2">instance.variable</span>. You can also use an object in place of the instance (<span class="inline2">object.variable</span>) which is fine if there is only one instance of that object, however it is not recommended if there are more than one, as it would just return the value from the first instance created for that object (which may change).</p>
<p>To understand how the dot accessor works with objects and instances, see <a data-xref="{title}" href="../GameMaker_Language/GML_Overview/Addressing_Variables_In_Other_Instances.htm">Addressing Variables In Other Instances</a>.</p>
<p>You can also access the scope of an instance or all instances of an object using <span class="inline2">with()</span>. See the <a data-xref="{title}" href="../GameMaker_Language/GML_Overview/Language_Features/with.htm">with</a> page for details on how it works using objects and instances.</p>
<h3>Functions Taking Only Objects or Instances</h3>
<p>There are built-in GML functions that operate on either an <strong>object handle</strong> or an <strong>instance handle</strong>, depending on the function.</p>
<p style="text-align: left; ">Functions that only take an object handle usually return information on all of its instances, such as <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_number.htm">instance_number</a></span>, on the object itself, such as <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Objects/object_get_name.htm">object_get_name</a></span>, and on one particular instance of the object, such as <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_nearest.htm">instance_nearest</a></span> and <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_create_layer.htm">instance_create_layer</a></span> (in this case, creating a new one). Another example is the function <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_change.htm">instance_change</a></span> which operates on the current instance and changes it to use a different object (and hence use its events).</p>
<p>Functions that only operate on instances mostly do so without arguments, as they operate on the instance executing the code. For example, <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_change.htm">instance_change</a></span> as previously mentioned, <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_copy.htm">instance_copy</a></span><span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Movement_And_Collisions/Movement/motion_add.htm">motion_add</a></span> and various other functions will operate on the current instance. There are functions that operate on instances via arguments, but they also accept object handles and are covered below under <strong>Mixed Functions</strong>.</p>
<h3>Functions Taking Both Objects and Instances</h3>
<p>There are built-in GML functions that take both an <strong>instance handle</strong> and an <strong>object handle</strong>.</p>
<p>The difference in most use cases is simple: passing an instance handle only modifies that <strong>one instance</strong>, and passing an object handle modifies <strong>all instances</strong> of the given object.</p>
<p>Pages for functions that take both types of values will explain the difference between passing either. Here are some common examples of functions that take both:</p>
<ul class="colour">
<li><strong>Functions that may affect multiple instances</strong>: There are functions that may operate on multiple <a href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/Instances.htm">instances</a> that take both instance and object handles. For example, <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_destroy.htm">instance_destroy</a></span> will destroy a single instance, but if you pass it an object handle, it will destroy all instances of that object. Similarly, <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_exists.htm">instance_exists</a></span> checks if a particular instance still exists in the room, however passing an object makes it check whether <em>any</em> instance of the object exists. Most other similar functions mirror this kind of behaviour.</li>
<li><strong>Collision functions</strong>: Common collision functions such as <span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Movement_And_Collisions/Collisions/place_meeting.htm">place_meeting</a></span><span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_place.htm">instance_place</a></span><span class="inline3_func"><a data-xref="{title}" href="../GameMaker_Language/GML_Reference/Movement_And_Collisions/Collisions/collision_circle.htm">collision_circle</a></span>, etc. take both instance and object handles. As you can guess, passing an instance makes them check for collisions only against that <em>specific</em> instance, while passing an object makes them check for collisions against <em>all </em>instances of the passed object.</li>
<li><strong><strong>Functions that affect a s</strong>ingle instance</strong>: There are functions that operate on single instances only, like the <a href="../GameMaker_Language/GML_Reference/Variable_Functions/Variable_Functions.htm">variable functions</a> that let you get or set variables on an instance using function calls. However these will let you pass object handles, which will only make the function operate on the first instance that was created for the object in the room (affected by the <a data-xref="{text}" href="../The_Asset_Editors/Room_Properties/Room_Properties.htm#creation_order">Instance Creation Order</a> if the instances were set up in the IDE). For such functions, passing object handles is <strong>NOT recommended</strong> as this behaviour only exists for legacy support.</li>
</ul>
<h3>Parents</h3>
<p>Using a <a href="../The_Asset_Editors/Object_Properties/Parent_Objects.htm">parent object</a> in any of the functions above is the same as passing all its child objects as well. The operation will include all instances of the given object and all instances of its child objects (and <em>their</em> child objects if they have any, and so on).</p>
<p> </p>
<p> </p>
<p> </p>
<!--</div>-->
<div class="footer">
<div class="buttons">
<div class="clear">
<div>Back: <a data-xref="{title}" href="Additional_Information.htm">Additional Information</a></div>
<div>Next: <a data-xref="{title}" href="Bitwise_Operators.htm">Bitwise Operators</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
</div>
<!-- KEYWORDS
Objects_vs_Instances
-->
<!-- TAGS
Objects_vs_Instances
-->
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ <h1>Biblioteka działań cząstek stałych</h1>
</ul>
<p>W kolejnych sekcjach omówiono wszystkie czynności związane z tworzeniem własnych systemów cząstek:</p>
<table class="dnd" style="text-align: left;margin-left:">
<colgroup>
<col style="width: 52px;" />
<col style="width: 476px;" />
</colgroup>
<tbody>
<tr style="height: 1px;">
<td class="icons" style="margin-left: 16px;"> </td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Adresowanie zmiennych w innych instancjach</h1>
<p>Zdecydowanie najbardziej powszechną i praktyczną metodą jest jednak użycie <i>zmiennej</i> po lewej stronie punktu, o ile zmienna ta<i> ma zapisany poprawny <b>identyfikator instancji</b></i>. Ilustrują to poniższe przykłady.</p>
<p class="code">// Example 1<br />
var _inst = instance_position(mouse_x, mouse_y, all);<br />
if (instance_exists(_inst)) <br />
if (instance_exists(_inst))<br />
{<br />
    _inst.speed = 0;<br />
}<br />
Expand Down Expand Up @@ -64,7 +64,7 @@ <h1>Adresowanie zmiennych w innych instancjach</h1>
<br />
// This will affect one instance of the object &quot;obj_Enemy&quot;<br />
var _enemy = instance_nearest(x, y, obj_Enemy);<br />
if (instance_exists(_enemy)) <br />
if (instance_exists(_enemy))<br />
{<br />
    with (_enemy)<br />
    {<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h2 id="h1">Changing The Static Struct</h2>
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../Structs.htm">Structs</a></div>
<div style="float:right">Next: <a data-xref="{title}" href="../Struct_Forbidden_Variables.htm">Struct Forbidden Variables</a></div>
<div style="float:right">Next: <a data-xref="{title}" href="../Commenting_Code.htm">Commenting Code</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sprite_add</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../../../assets/css/default.css" type="text/css" />
<script src="../../../../../assets/scripts/main_script.js"></script>
<meta name="rh-authors" content="Mark Alexander" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sprite_add_from_surface</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../../../assets/css/default.css" type="text/css" />
<script src="../../../../../assets/scripts/main_script.js"></script>
<meta name="rh-authors" content="Mark Alexander" />
Expand Down Expand Up @@ -78,7 +78,7 @@ <h4>Przykład:</h4>
var i;<br />
for (i = 1; i &lt; 8; i += 1)<br />
{<br />
    sprite_add_from_surface(spr_custom, surf, i, 0, 32, 32, true, true);<br />
    sprite_add_from_surface(spr_custom, surf, i, 0, 32, 32, false, false);<br />
}</p>
<p>Powyższy kod tworzy stronę <span class="notranslate">sprite</span> z powierzchni indeksowanej w zmiennej &quot;surf&quot;, przypisując jej indeks do zmiennej &quot;spr_Custom&quot;, a następnie używa strony <span class="inline">for</span> <span class="notranslate">loop</span> do poruszania się po powierzchni i przechwytywania różnych fragmentów, które są dodawane do strony <span class="notranslate">sprite</span> jako obrazy podrzędne.</p>
<p> </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h4>Przykład:</h4>
draw_sprite(spr_Body, 0, 0, 0);<br />
draw_sprite(spr_Clothes, 0, 0, 0);<br />
draw_sprite(spr_Hair, 0, 0, 0);<br />
spr_custom = sprite_create_from_surface(surf, 0, 0, 32, 32, true, true, 16, 16);<br />
spr_custom = sprite_create_from_surface(surf, 0, 0, 32, 32, false, false, 16, 16);<br />
surface_reset_target();<br />
surface_free(surf);</p>
<p>Powyższy kod tworzy powierzchnię i przechowuje jej indeks w zmiennej lokalnej &quot;surf&quot;. Następnie celuje w tę powierzchnię, oczyszcza ją i rysuje kilka <span class="notranslate">sprites</span> jeden na drugim. Na koniec tworzy nową stronę <span class="notranslate">sprite</span> z połączonego obrazu narysowanego na powierzchni i przypisuje jej indeks do zmiennej &quot;spr_Custom&quot;, a następnie zwalnia pamięć używaną przez powierzchnię.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>file_find_close</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css" />
<script src="../../../../assets/scripts/main_script.js"></script>
<meta name="rh-authors" content="Mark Alexander" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>string_format</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css" />
<script src="../../../assets/scripts/main_script.js"></script>
<meta name="rh-authors" content="Mark Alexander" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1><span data-field="title" data-format="default">variable_clone</span></h1>
<br />
When cloning a method whose <span class="inline2">self</span> does <em>not</em> exist in the struct being cloned, the new method will be unbound, i.e. <a href="method_get_self.htm">its self</a> will be <span class="inline2">undefined</span>.
</p>
<p class="note"><span data-conref="../../../assets/snippets/Tag_note.hts"> </span> The built-in <a data-xref="{title}" href="../Data_Structures/Data_Structures.htm">Data Structures</a> and <a data-xref="{title}" href="../Asset_Management/Instances/Instances.htm">Instances</a> are <em>not</em> cloned; for this type of variable the actual value (data structure reference or instance reference, respectively) is copied.</p>
<p class="note"><span data-conref="../../../assets/snippets/Tag_note.hts"> </span> The built-in <a data-xref="{title}" href="../Data_Structures/Data_Structures.htm">Data Structures</a> and <a data-xref="{title}" href="../Asset_Management/Instances/Instances.htm">Instances</a> are <em>not</em> cloned; for this type of variable the actual value (data structure reference or instance handle, respectively) is copied.</p>
<p class="note"><span data-conref="../../../assets/snippets/Tag_note.hts"> </span> Built-in structs, such as the structs related to sequences and animation curves, cannot be cloned using this function.</p>
<p> </p>
<h4>Syntax:</h4>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Manual/contents/assets/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ table.dnd {
width: 50%;
background: #282828;
box-shadow: 0px 0px 0px #282828;
float: left;
margin-left: 10px;
}
td.icons {
background: #282828;
Expand Down
14 changes: 14 additions & 0 deletions Manual/contents/assets/snippets/Note_wont_work_on_html5_and_gx.hts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<meta name="topic-comment" content="" />
<title>Note_wont_work_on_html5_and_gx</title>
<link rel="stylesheet" type="text/css" href="../css/default.css" />
</head>
<body>
<p class="note"><span class="note">NOTE</span> This function will not work on the HTML5 and <span data-keyref="Gxgames">GX.games</span> targets.</p>
</body>
</html>
Loading

0 comments on commit 80ed197

Please sign in to comment.