From dfa28a29c86f1de68dc8274a62854cd92d45c960 Mon Sep 17 00:00:00 2001
From: gurpreetsinghmatharoo
Date: Wed, 15 Jan 2025 14:57:38 +0530
Subject: [PATCH 1/9] docs(feature): Documented examples for when self and
other change
---
.../GML_Overview/Instance Keywords/other.htm | 39 +++++++++++++++++++
.../GML_Overview/Instance Keywords/self.htm | 26 +++++++++++++
2 files changed, 65 insertions(+)
diff --git a/Manual/contents/GameMaker_Language/GML_Overview/Instance Keywords/other.htm b/Manual/contents/GameMaker_Language/GML_Overview/Instance Keywords/other.htm
index edd41c570..11d57dddd 100644
--- a/Manual/contents/GameMaker_Language/GML_Overview/Instance Keywords/other.htm
+++ b/Manual/contents/GameMaker_Language/GML_Overview/Instance Keywords/other.htm
@@ -45,8 +45,47 @@
When 'other' changes
This section will describe those cases in relation to how other changes:
Inside a with block, other will be the instance or struct that called the with() function
+
+
value = 40;
+
+ var _struct = {
+ value : 99
+ }
+
+ with (_struct)
+ {
+ show_debug_message(other.value); // Prints 40
+ }
+
+
When calling a method that is bound to an instance or a struct, other will be the instance or struct that called that method
+
+
value = 40;
+
+ var _struct = {
+ value : 99,
+ func : function () {
+ return other.value;
+ }
+ }
+
+ show_debug_message(_struct.func()); // Prints 40
+
+
When calling an unbound constructor function, other will be the instance or struct that called that function. If the constructor is bound as a method, then other will be the instance or struct to which the constructor method is bound.
+
+
value = 40;
+
+ item = function () constructor {
+ value = 99;
+
+ copied_value = other.value;
+ }
+
+ my_item = new item();
+ show_debug_message(my_item.copied_value); // Prints 40
+
+
When stored as a reference through a struct literal, covered below under "'other' as a reference".
When calling a method that is bound to an instance or a struct, the self during the execution of that function will be the instance or struct to which the method is bound
+
+
value = 40;
+
+ var _struct = {
+ value : 99,
+ func : function () {
+ return self.value;
+ }
+ }
+
+ show_debug_message(_struct.func()); // Prints 99
+
+
When calling a constructor function, self will refer to the new struct that is being generated as a result of that function.
+
+
value = 40;
+
+ item = function () constructor {
+ value = 99;
+
+ copied_value = self.value;
+ }
+
+ my_item = new item();
+ show_debug_message(my_item.copied_value); // Prints 99
+
+
When stored as a reference through a struct literal, covered below under "'self' as a reference".
In all of these cases, when self changes to a new scope, other will be set to be the previous scope. The only exception is when a bound constructor method is called. This is described more in When 'other' changes.
This section will describe those cases in relation to how other changes:
+
This section describes those cases in relation to how other changes:
Inside a with block, other will be the instance or struct that called the with() function
@@ -58,20 +58,24 @@
When 'other' changes
}
+
Using dot notation on a struct or instance (struct.variable)
When calling a method that is bound to an instance or a struct, other will be the instance or struct that called that method
value = 40;
- var _struct = {
+ var _struct = instance_create_depth(0, 0, 0, Object2, {
value : 99,
func : function () {
return other.value;
}
- }
+ });
+
+ var _func = _struct.func;
- show_debug_message(_struct.func()); // Prints 40
+ show_message(_func()); // Prints 40
+
In the above case, calling _struct.func() directly would return 99, as the scope first changes to _struct due to dot notation, and then it changes again when the bound method is called, making the other the previous scope at the moment the method is called, which is the struct (with value set to 99)
When calling an unbound constructor function, other will be the instance or struct that called that function. If the constructor is bound as a method, then other will be the instance or struct to which the constructor method is bound.
value = 40;
@@ -91,8 +95,8 @@
When 'other' changes
Legacy other Behaviour
In previous versions of GameMakerother only changed in the following cases:
-
As part of the with statement.
-
When new is called when a constructor is executed other is set to the self at the point that new was called.
+
As part of the with statement
+
When new is called when a constructor is executed other is set to the self at the point that new was called
In this example you can see that we have a local variable called val and we want it to set the instance variable with the same name in the newly created object instance. To identify the instance variable correctly and tell GameMaker to set it in the instance calling the code block, we use the self keyword.
self is used in the same way with structs to reference member variables of the struct. It can also be used within constructor functions to reference the struct being generated from the constructor.
When 'self' changes
-
Within an event, the current self will change in the following situations:
+
Within an event or script, the current self will change in the following situations:
When calling a method that is bound to an instance or a struct, the self during the execution of that function will be the instance or struct to which the method is bound
+
Using dot notation on a struct or instance (struct.variable)
+
When calling a method that is bound to an instance or a struct, the self during the execution of that method will be the instance or struct to which the method is bound
value = 40;
- var _struct = {
+ var _struct = instance_create_depth(0, 0, 0, Object2, {
value : 99,
func : function () {
return self.value;
}
- }
+ });
+
+ var _func = _struct.func;
- show_debug_message(_struct.func()); // Prints 99
+ show_message(_func()); // Prints 99
When calling a constructor function, self will refer to the new struct that is being generated as a result of that function.
The benefit of doing a unity build is that builds are faster but the down side is that it does a full build each time so even if you change a single part of the code it will build everything again without using any cached files. This has been added specifically for the Xbox One export using the YYC although it can be called for other builds (YYC only). For more information on unity builds, please see here.
"AllowReentrantStatic" - This pragma reverts static initialisation to the old re-entrant initialisation behaviour of GameMaker versions up to 2024.8. It is a project-wide setting and so cannot be put around code sections. The following code enables this old behaviour:
-
gml_pragma( "AllowReentrantStatic", true);
+
gml_pragma("AllowReentrantStatic", true);
You should only use this in existing projects that make use of the old behaviour. GMRT (GameMaker Runtime) will no longer allow it.
+
"MarkTagAsUsed" - When "Automatically remove unused assets when compiling" is enabled in the Game Options, any unused assets are stripped from the compiled game. This can break games that dynamically load assets at runtime. With this pragma you can mark the Tags that should not be stripped and any assets with the assigned tags will always be present in the compiled game package.
+
By default, any assets that are unused or not referenced directly in your code are stripped from the game's executable. This can be disabled through the Game Options or you can mark tags that should always be preserved through gml_pragma("MarkTagAsUsed", <tags>).
How Different Targets Build
Each target option saves to a platform-specific format, listed below:
As mentioned in various of the sections above, the asset browser gives you the ability to add tags to individual assets as well as to group folders. Tags are a very powerful tool, not only for organising and filtering the assets listed in the asset browser, but also when programming your game in general, as you can use assigned tags in code.
To create a tag you need to use the RMB menu on an asset and then select the Edit Tags option. This will bring up the Tag Editor where you can type in the tag you want to use, and then either press or type a comma to apply it:
You can assign multiple tags to a single item, and you can also use or / along with the left mouse button to select multiple assets and assign a tag to all of them at once. Once added, all tags will be visible under the Quick Access menu and also in the Filter options (as explained in the sections above), and so can be used to quickly filter the asset list and show only those items with the chosen tag or tags.
Enable Copy on Write Behaviour for Arrays: This enables the deprecated Copy on Write array behaviour.
-
Automatically remove unused assets when compiling: This option enables automatic removal of unused assets when compiling. When enabled, any unused assets that are removed will be logged in the compile output of the project. This setting is enabled by default. This does not affect assets used from the Prefab Library (except for those that have been duplicated into the project) as unused Prefab assets will always be removed during compilation.
+
Automatically remove unused assets when compiling: This option enables automatic removal of unused assets when compiling. When enabled, any unused assets that are removed will be logged in the compile output of the project. This setting is enabled by default. You can mark tags as used with gml_pragma("MarkTagAsUsed", <tags>) and any assets with the specified tags will not be stripped when this option is enabled. This option does not affect assets used from the Prefab Library (except for those that have been duplicated into the project) as unused Prefab assets will always be removed during compilation.
The Main Options section also contains a menu for Template Info.
The Asset Browser will also have other Game Options available to you depending on the target platforms that are available for the licence that you have and not all of them may be available or visible.
The code above converts the handle of a sprite named spr_player to its string representation (handle_as_string), and then back into a handle (h). It then outputs each of the created instance variables in a debug message, along with its type. This prints the following:
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.
The values of the handle variables are implicitly converted to their string representation to display them.
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/Manual/contents/assets/snippets/Handle_Format.hts b/Manual/contents/assets/snippets/Handle_Format.hts
index 5745c5e41..0ed57f743 100644
--- a/Manual/contents/assets/snippets/Handle_Format.hts
+++ b/Manual/contents/assets/snippets/Handle_Format.hts
@@ -9,6 +9,6 @@
-