-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into develop
- Loading branch information
Showing
15 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Manual/contents/Additional_Information/Objects_vs_Instances.htm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+3.49 KB
(210%)
.../contents/assets/Images/Scripting_Reference/GML/Reference/Sprites/spr_strip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.06 KB
(89%)
Manual/contents/assets/Images/Settings/Configs_TargetManager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Manual/contents/assets/snippets/Note_wont_work_on_html5_and_gx.hts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.