Skip to content

Commit

Permalink
docs(general): Precreation code update
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreetsinghmatharoo committed Nov 20, 2024
1 parent 474be3f commit 904236d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ <h1><span data-field="title" data-format="default">room_get_info</span></h1>
<tr>
<td><span class="inline">pre_creation_code</span></td>
<td><span data-keyref="Type_Function_Script"><a href="../../../GML_Overview/Script_Functions.htm" target="_blank">Script Function</a></span></td>
<td>The index of the script function that holds the pre-creation code for this specific instance, i.e. the overrides for its <a data-xref="{title}" href="../../../../The_Asset_Editors/Object_Properties/Object_Variables.htm">Object Variables</a> as set in the Room Editor.</td>
<td>The index of the script function that holds the pre-creation code for this specific instance, i.e. the overrides for its <a data-xref="{title}" href="../../../../The_Asset_Editors/Object_Properties/Object_Variables.htm">Object Variables</a> as set in the Room Editor. See: <a data-xref="{text}" href="../../../../The_Asset_Editors/Object_Properties/Object_Variables.htm#h">Pre-creation Code</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ <h1><span data-field="title" data-format="default">Object Variables</span></h1>
<h2>Object Variables And Child Objects</h2>
<p>An important feature of the <span data-field="title" data-format="default">Object Variables</span> is that they are <em>inherited </em>by any child objects that you have in the Asset Browser (see the section on <a data-xref="{title}" href="Parent_Objects.htm">Parent Objects</a> for more information), which means that you can then choose to override or change any or all of them if you wish.</p>
<p>When you create a child object of another object asset that has variables defined for it, these will show up in the <span data-field="title" data-format="default">Object Variables</span> window like this:</p>
<p><img alt="Object Editor Variable In A Child Object" class="center" src="../../assets/Images/Asset_Editors/Editor_Object_ChildVariables.png" />You can see in the top image that the Parent object has four Object Variables and in the bottom image these are also shown, only &quot;greyed out&quot; and have the<strong> Inherited From Parent</strong> <img alt="Inherited From Parent Icon" class="icon" src="../../assets/Images/Icons/Icon_InheritedVariable.png" /> icon to indicate that they have been inherited. These inherited variables can then be edited if you click the <strong>Override Variable</strong> <img alt="Override Variable Icon" class="icon" src="../../assets/Images/Icons/Icon_OverrideVariable.png" /> button, so you can then adjust the range slider or values, or select different items from lists, etc. Note that when you edit a parent variable <em>you can only change the defined value</em> but not the name, nor can you change the variable options. Also note that you can add in new Object Variables to child objects as well (and in the example image above you can see that &quot;Character Type&quot; is a new Object Variable only for the child object).</p>
<p><img alt="Object Editor Variable In A Child Object" class="center" src="../../assets/Images/Asset_Editors/Editor_Object_ChildVariables.png" style="cursor: nesw-resize;" />You can see in the top image that the Parent object has four Object Variables and in the bottom image these are also shown, only &quot;greyed out&quot; and have the<strong> Inherited From Parent</strong> <img alt="Inherited From Parent Icon" class="icon" src="../../assets/Images/Icons/Icon_InheritedVariable.png" /> icon to indicate that they have been inherited. These inherited variables can then be edited if you click the <strong>Override Variable</strong> <img alt="Override Variable Icon" class="icon" src="../../assets/Images/Icons/Icon_OverrideVariable.png" /> button, so you can then adjust the range slider or values, or select different items from lists, etc. Note that when you edit a parent variable <em>you can only change the defined value</em> but not the name, nor can you change the variable options. Also note that you can add in new Object Variables to child objects as well (and in the example image above you can see that &quot;Character Type&quot; is a new Object Variable only for the child object).</p>
<p>If you have edited an inherited Object Variable, then you can click the Delete <img alt="Delete Variable Icon" class="icon" src="../../assets/Images/Icons/Icon_DeleteVariable.png" /> button to remove the edit, but not the variable. The variable will still be inherited from the parent, but will use the parent default value again. If you need to completely remove the variable, then you must do this from the parent object.</p>
<h2 id="h">Pre-creation Code</h2>
<p>Pre-creation code is any code generated by the compiler to initialise <span data-field="title" data-format="lower-alpha">object variables</span>. This includes the variables that you override in an instance added to the Room Editor. It runs before the Create event and before the variables in the <span class="inline2">var_struct</span> are assigned (when using <span class="inline3_func"><a data-xref="{title}" href="../../GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_create_depth.htm">instance_create_depth</a></span> or <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>). The pre-creation code for variables that you override in the Room Editor can be found in the struct returned by <span class="inline3_func"><a data-xref="{title}" href="../../GameMaker_Language/GML_Reference/Asset_Management/Rooms/room_get_info.htm">room_get_info</a></span>.</p>
<p>This makes the order of variable initialisation in an instance as follows:</p>
<ol class="colour">
<li>The pre-creation code runs for the new instance, assigning it the variables set in the Variable Definitions.</li>
<li>The pre-creation code generated for instances added to the room in the Room Editor runs.</li>
<li>The pre-creation code runs for the new instance, assigning it the variables set in the Variable Definitions and any overrides if it was placed in the Room Editor and variables were modified.</li>
<li>The variables in the <span class="inline2">var_struct</span> are assigned.</li>
<li>The Create event runs for the instance.</li>
</ol>
Expand Down

0 comments on commit 904236d

Please sign in to comment.