diff --git a/Manual/GenerateKeyboardShortcutTableFromJson.py b/Manual/GenerateKeyboardShortcutTableFromJson.py index e01ba4c91..bb5a4cd7f 100644 --- a/Manual/GenerateKeyboardShortcutTableFromJson.py +++ b/Manual/GenerateKeyboardShortcutTableFromJson.py @@ -1,21 +1,18 @@ -### Python script to generate copy-pasteable HTML tables from JSON files +### Python script to generate copy-pasteable HTML tables from JSON file ### -### Provide the full directory path to the .json files as the command line argument. +### Provide the full directory path to the .json file as the command line argument. ### The output HTML file will also be placed there. -### For example: CMD > python GenerateKeyboardShortcutTableFromJson.py "C:/Users/Dev/Documents/GitHub/ameMaker-Manual/Manual/" -name_as_desc -env beta -update_rh_vars +### For example: CMD > python GenerateKeyboardShortcutTableFromJson.py "C:/Users/Dev/Documents/GitHub/GameMaker-Manual/Manual/" -name_as_desc -env beta ### ### You can provide a few optional arguments: ### ### -name_as_desc: Add this to write the hotkey's name as the description. -### -env: Provide this, followed by the environment in which you want to look for the JSON files +### -env: Provide this, followed by the environment in which you want to look for the JSON file ### (one of: "dev", "lts", "beta", "prod") ### Note: only works on Windows! ### -update_rh_vars: Add this to update the RoboHelp variables ### A RH variable is written (or updated if exists) for every Win/Mac shortcut ### For example: Hotkey_Create_Asset_Win, Hotkey_Create_Asset_Mac -### -### Important: Technically, the JSON cannot contain trailing commas, this isn't supported -### using the built-in json module. Though it is supported through the yy_load function. ### import sys @@ -30,18 +27,8 @@ # Unique modifier keys mods = set() -def yy_load(file): - """ Load json from a file that possibly contains trailing commas """ - # Do some tricky regex substitution - # so we can use the json module - data_string = ''.join(file.readlines()) - data_string = re.sub("(,)(\s*[]}])","\g<2>", data_string) - - # Now we can import using the json module - return json.loads(data_string) - # Utility functions -def get_combo_string(combo): +def get_combo_string(combo, replace_in_names=[]): global mods if not combo: combo_string = "" @@ -55,11 +42,14 @@ def get_combo_string(combo): else: # This is a regular hotkey combo_string = " + ".join([*modifier, combo['Keys']]) + + if replace_in_names: + for item in replace_in_names: + combo_string = combo_string.replace(item[0], item[1]) return combo_string # Default names -fname_win_hotkeys = "default_hotkeys.json" -fname_mac_hotkeys = "mac_hotkeys.json" +fname_hotkeys = "default_hotkeys.json" install_dirs = { "dev": "GameMaker-Dev", @@ -98,10 +88,9 @@ def get_combo_string(combo): exit() # Check if files exist -fpath_win = in_dir + os.sep + fname_win_hotkeys -fpath_mac = in_dir + os.sep + fname_mac_hotkeys -if not os.path.isfile(fpath_win) or not os.path.isfile(fpath_mac): - print("ERROR - One or more files doesn't exist. Exiting...") +fpath_win = in_dir + os.sep + fname_hotkeys +if not os.path.isfile(fpath_win): + print("ERROR - Shortcuts file doesn't exist. Exiting...") exit() # Data structures @@ -109,11 +98,10 @@ def get_combo_string(combo): shortcuts = dict() # maps shortcut name => shortcut data shortcuts_per_location = OrderedDict() # stores shortcuts under locations -# First read the Windows defaults file +# Read the defaults file with open(fpath_win, 'r', encoding="utf-8") as f: # Load all the data - # input = json.load(f) # risk of errors if trailing commas are present - input = yy_load(f) # regex-replace variety that fixes things + input = json.load(f) # risk of errors if trailing commas are present # Add items under their respective locations (i.e. "group" per location) for shortcut in input: @@ -139,6 +127,20 @@ def get_combo_string(combo): # "Localisation": combo['Localisation'] } + # Store platform overrides, if there are any + if 'PlatformOverrides' in shortcut and shortcut['PlatformOverrides']: + for override in shortcut['PlatformOverrides']: + if override['Platform'] != 'MacOs': + continue + + # Get this shortcut's Mac combo(s) + cbo = override['Combo'] + combos = [cbo] if type(cbo) is not list else cbo + combo_strings = [get_combo_string(combo, replace_in_names=[("Windows", "Command")]) for combo in combos] + + # Assign to final output + shortcuts[name]['mac_combo'] = combo_strings + # Store name of shortcut under all its locations loc = shortcut['Location'] locations = [loc] if (type(loc) == str) else loc @@ -151,28 +153,6 @@ def get_combo_string(combo): # Add the shortcut shortcuts_per_location[location][name] = name -# Then add the combos in the macOS defaults file -with open(fpath_mac, 'r') as f: - # Load all the data - input = yy_load(f) - - # Add items under their respective locations - for shortcut in input: - # Get unique name - name = shortcut['Name'] - - # Nothing to do for unlisted shortcuts - if name not in shortcuts: - continue - - # Get this shortcut's combo(s) - cbo = shortcut['Combo'] - combos = [cbo] if type(cbo) is not list else cbo - combo_strings = [get_combo_string(combo) for combo in combos] - - # Just overwrite the macOS combo under the right name here - shortcuts[name]['mac_combo'] = combo_strings - # Generate HTML html = "" for location in shortcuts_per_location: diff --git a/Manual/_page_generation/Template_Code_Page.htm b/Manual/_page_generation/Template_Code_Page.htm index a4d5eb900..5969fe979 100644 --- a/Manual/_page_generation/Template_Code_Page.htm +++ b/Manual/_page_generation/Template_Code_Page.htm @@ -16,7 +16,6 @@

INSERT_TITLE

Keyword Description Goes Here.

-

Additional Information Goes Here.

 

Syntax:

(arguments);

diff --git a/Manual/contents/Additional_Information/Additional_Information.htm b/Manual/contents/Additional_Information/Additional_Information.htm index 1f23aca17..6610fdc60 100644 --- a/Manual/contents/Additional_Information/Additional_Information.htm +++ b/Manual/contents/Additional_Information/Additional_Information.htm @@ -18,6 +18,7 @@

Additional Information

This section of the manual contain a collection of miscellaneous articles related to programming and the way the GameMaker Language works. The following articles are designed as companion articles to further expand your understanding of how GameMaker works and how to get the most from the different language features available:

 

 

@@ -42,7 +44,7 @@

Additional Information
Next: GameMaker Language
-

© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved
+

Objects vs. Instances

+

One of the first assets you work with in GameMaker are Objects. An object lets you define how something in your game behaves (e.g. a player or enemy).

+

Then in The Room Editor, you drag an object into a room, so it actually appears in-game. That's where an object stops and an instance begins.

+

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.

+

Difference At Runtime

+

Understanding the difference between objects and instances is important as they both exist as resources at runtime.

+

Instances 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. Objects on the other hand continue to exist as background resources, and they can be modified and used to create new instances.

+

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.

+

Accessing Variables

+

You can access variables from an instance via dot notation, i.e. instance.variable. You can also use an object in place of the instance (object.variable) 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).

+

To understand how the dot accessor works with objects and instances, see Addressing Variables In Other Instances.

+

You can also access the scope of an instance or all instances of an object using with(). See the with page for details on how it works using objects and instances.

+

Functions Taking Only Objects or Instances

+

There are built-in GML functions that operate on either an object handle or an instance handle, depending on the function.

+

Functions that only take an object handle usually return information on all of its instances, such as instance_number, on the object itself, such as object_get_name, and on one particular instance of the object, such as instance_nearest and instance_create_layer (in this case, creating a new one). Another example is the function instance_change which operates on the current instance and changes it to use a different object (and hence use its events).

+

Functions that only operate on instances mostly do so without arguments, as they operate on the instance executing the code. For example, instance_change as previously mentioned, instance_copymotion_add 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 in the next section.

+

Functions Taking Both Objects and Instances

+

There are built-in GML functions that take both an instance handle and an object handle.

+

The difference in most use cases is simple: passing an instance handle only modifies that one instance, and passing an object handle modifies all instances of the given object.

+

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:

+ +

Parents

+

Using a parent object 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 their child objects if they have any, and so on).

+

 

+

 

+

 

+ + + + + + \ No newline at end of file diff --git a/Manual/contents/Additional_Information/Obsolete_Functions.htm b/Manual/contents/Additional_Information/Obsolete_Functions.htm index 1a616fb25..34073e659 100644 --- a/Manual/contents/Additional_Information/Obsolete_Functions.htm +++ b/Manual/contents/Additional_Information/Obsolete_Functions.htm @@ -4,7 +4,7 @@ Obsolete Functions - + @@ -15,11 +15,11 @@

Obsolete Functions

-

Here you can find a list of all the functions that have been made obsolete when you compare GameMaker to legacy versions of the product. The functions listed here will be converted into compatibility scripts when you import a *.yyz made with a legacy version, and you can continue to work on the project as before. However, we recommend that you revise all the compatibility scripts created in a project, and ensure that future projects use the new functions/methods of working rather than depend on these scripts.

+

Here you can find a list of all the functions that have been made obsolete when you compare GameMaker to legacy versions of the product. The functions listed here will be converted into Compatibility Scripts when you import a *.yyz made with a legacy version, and you can continue to work on the project as before. However, we recommend that you revise all the compatibility scripts created in a project, and ensure that future projects use the new functions/methods of working rather than depend on these scripts.

Backgrounds

-

In legacy GameMaker you had a separate background resource, where you could add images to be used as backgrounds. In GameMaker all images are considered sprites, and the use you put them too will depend on the layer they are assigned to in the room. This means that there is no longer a "background" resource, and it also means that the following functions are obsolete:

- +

In legacy GameMaker you had a separate background resource, where you could add images to be used as backgrounds. In GameMaker all images are considered sprites, and the use you put them too will depend on the layer they are assigned to in the room. This means that there is no longer a "background" resource, and it also means that the following functions are obsolete:

+
@@ -115,7 +115,7 @@

Obsolete Functions

draw_background

Legacy GameMaker lso had a number of different background variables that accessed the global background array. These are no longer required in GameMaker:

- +
@@ -163,13 +163,13 @@

Obsolete Functions

-

You can find out more about Background Layers from the section on the Room Editor, and for more information on the functions that control background layers using code see Background Layers.

+

You can find out more about Background Layers from the section on The Room Editor, and for more information on the functions that control background layers using code see Background Layers.

 

Tiles

As with backgrounds (explained above) the tile resource from legacy GameMaker no longer exists, and instead we have Tile Sets in GameMaker. In legacy GameMaker, tiles used a background resource and were placed at different depths in the room editor or through code, however the method used was not terribly flexible and was also not that efficient. To address these issues, in GameMaker tilesets are now created from a sprite resource, and can have various different properties (like animation or auto-tiling). They are then placed on a tilemap layer within the room editor or through code. Due to these changes the following functions are now obsolete:

- +
@@ -235,8 +235,8 @@

Obsolete Functions

Objects

-

The way objects are treated in GameMaker has changed slightly due to the introduction of layers in the room editor. There still exists the "depth" variable, but it is now only really used for compatibility and you can no longer get or set the depth for objects, only instances. This makes the following functions obsolete:

-
tile_get_x
+

The way objects are treated in GameMaker has changed slightly due to the introduction of layers in the Room Editor. There still exists the "depth" variable, but it is now only really used for compatibility and you can no longer get or set the depth for objects, only instances. This makes the following functions obsolete:

+
@@ -246,13 +246,13 @@

Obsolete Functions

object_get_depth
-

You can find out more about object resources from the manual section on the Object Editor and on the functions that control objects using code from the section Objects.

+

You can find out more about object resources from the manual section on The Object Editor and on the functions that control objects using code from the section Objects.

 

Sounds

Legacy GameMaker had two different sound API's, one which used the deprecated sound_ functions (that was only really valid for the HTML5 target platform), and the other which used the audio_ functions. The audio API has been improved and expanded in GameMaker, making the legacy functions listed below obsolete:

- +
@@ -295,13 +295,13 @@

Obsolete Functions

sound_name
-

You can find out more about audio resources from the manual section on the Sound Editor and on the functions that control audio using code from the section on Audio

+

You can find out more about audio resources from the manual section on The Sound Editor and on the functions that control audio using code from the section on Audio

 

D3D

When using 3D models or primitives in legacy GameMaker, you had to use the d3d_ functions. These used an obsolete API for drawing and in many cases were not related strictly to Direct 3D API, or even to using 3D itself. With the advent of vertex buffers, matrices and cameras in GameMaker, the following functions have been made obsolete:

- +
@@ -486,7 +486,7 @@

Obsolete Functions

View Variables And Window Functions

With the advent of the camera functions in GameMaker, it means that a number of view variables are no longer required, specifically those referring to the view into the room rather than the view_port (which is still used). There are also a few functions for controlling how things are displayed that were available in legacy versions of GameMaker Studio which are also no longer appropriate. These variables and functions are listed below:

-
+
@@ -523,7 +523,7 @@

Obsolete Functions

3rd Party Support

GameMaker moves a lot of built in functionality from previous versions into extensions, meaning that the following 3rd party support functions are considered obsolete:

-
view_object
+
@@ -634,13 +634,13 @@

Obsolete Functions

ads_enable
-

You can get our official extensions for advertising and other APIs from the Marketplace Page.

+

You can get our official extensions for advertising and other APIs from the Marketplace Page.

 

GML Visual Actions

Both legacy GameMaker and GameMaker have a visual scripting GML Visual interface for creating your games, however the way it is handled in GameMaker is quite different to the previous methods used. Previously, all GML Visual actions had their own corresponding function which worked "behind the scenes" to get the desired results, however this was not very transparent and added in extra overheads to the function calls, resulting in poorer performance. In GameMaker this has been changed, and now all actions compile to pure code (and can be shown as such if required), meaning that the following action functions are obsolete:

- +
@@ -859,9 +859,9 @@

Obsolete Functions

Vectors and Matrices

The data type used to store vectors and matrices in GameMaker are Arrays. Therefore, the following functions relating to working with vectors and matrices were removed: 

-
action_path_old
+
- + @@ -916,10 +916,10 @@

Obsolete Functions

Back: Additional Information
-
Next: The File System
+
Next: The Marketplace
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

Game Action Library

Game Action LibraryThe Game action library is related to things that affect the main game loop and has the following actions:

-

 

is_vec3 is_vec4 is_matrix
@@ -40,12 +39,6 @@

Game Action Library

 

 

 

-

 

-

 

-

 

-

 

-

 

-

 

Instance Variable Action Library

-

Instance Variable Action Library

-

The Instance Variables actions are designed to get you started when creating a game and are used to create and maintain specific instance scope variables for score, lives and health (you can find out more about variable - scope here). These actions will create these variables for you at any time they are used and are meant more for convenience or for beginners, and if you need more - complex control over game values you should be making your own variables using the appropriate actions (see here)

+

Instance Variable Action Library

+

The Instance Variables actions are designed to get you started when creating a game and are used to create and maintain specific instance scope variables for score, lives and health (you can find out more about variable scope here). These actions will create these variables for you at any time they are used and are meant more for convenience or for beginners, and if you need more complex control over game values you should be making your own variables using the appropriate actions (see here)

The following actions exist for using these Instance Variables:

-

 

-

 

@@ -66,17 +62,6 @@

Instance Variable Action Library

 

 

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

Miscellaneous Action Library

Miscellaneous Action LibraryThis action library contains those actions that don't fit into any other library category. The following Miscellaneous actions exist:

-

 

@@ -32,12 +31,6 @@

Miscellaneous Action Library

 

 

 

-

 

-

 

-

 

-

 

-

 

-

 

Path Action Library

-

Paths Action LibraryThe Path library has actions for dealing with path resource made in the - Path Editor:

-

 

+

Paths Action LibraryThe Path library has actions for dealing with path resource made in the Path Editor:

@@ -50,13 +48,6 @@

Path Action Library

 

 

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

Room Action Library

-

Room Action LibraryThe Room library permits you to change and check game rooms, based on the order defined in the Room Manager. Note that all actions which change the room will also trigger the - Other - Room Events - .

+

Room Action LibraryThe Room library permits you to change and check game rooms, based on the order defined in the Room Manager. Note that all actions which change the room will also trigger the Other - Room Events .

The following actions are available:

-

 

@@ -56,16 +52,6 @@

Room Action Library

 

 

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

-

 

Addressing Variables In Other Instances

-

In the sections dedicated to variables you found out how to create and use variables within a single instance, or on a global scope, but what happens if you want one instance to access a variable in another, different instance? There are many cases when you may want to do this, for example in a collision with a bullet object, you may want to find out how much damage the bullet does by accessing a variable in the bullet, or you might want to stop the motion of all the balls in a puzzle, or you might want to move the main character to a particular position, or any number of other situations you typically come across in any game. Thankfully the GameMaker Language comes equipped with mechanisms to achieve this.

+

In the sections dedicated to variables you found out how to create and use variables within a single instance, or on a global scope, but what happens if you want one instance to access a variable in another, different instance?

+

There are many cases when you may want to do this, for example in a collision with a bullet object, you may want to find out how much damage the bullet does by accessing a variable in the bullet, or you might want to stop the motion of all the balls in a puzzle, or you might want to move the main character to a particular position, or any number of other situations you typically come across in any game. Thankfully the GameMaker Language comes equipped with mechanisms to achieve this.

One of the most common methods of accessing or changing a variable in another instance is to use its object name as an identifier, and then use a point . to tell GameMaker that the variable being referenced should be assigned or changed within that specific object's instance. This is known as "dot notation", and its syntax is as follows:

<object_id>.<variable> = <value>; 

In practice it would look like this:

obj_ball.speed = 0;

-

With the above code you are setting the speed of an instance of obj_ball. However if you have more than one instance of the given object in the room, then it will apply to ALL of them equally - unless you are using HTML5, in which case it will affect only one, but you have no way of knowing which one it will affect - so if you need to access all instances of an object, you should be using with, as that is 100% cross-platform compatible. In general, this format should only be used when you have a single instance of the object in the room, or (as you will see in the next part) when you have a specific instance ID.

+

With the above code you are setting the speed of an instance of obj_ball. However if you have more than one instance of the given object in the room, then it will apply to ALL of them equally - unless you are using HTML5, in which case it will affect only one, but you have no way of knowing which one it will affect - so if you need to access all instances of an object, you should be using with, as that is 100% cross-platform compatible. In general, this format should only be used when you have a single instance of the object in the room, or (as you will see in the next part) when you have a specific instance handle.

+

 Reading a variable using an object handle with dot notation (e.g. spd = obj_ball.speed) will return the value from the first instance of that object that was created in the room. This is affected by the Instance Creation Order if the instances were set up in The Room Editor.

You can also access a single instance of an object when there are multiple instances within the room using the unique instance name to tell GameMaker exactly which instance we wish to address. The instance name constant is the unique identifying constant that is given to each and every instance added to a room in your game. You can find this constant by double-clicking on an instance in The Room Editor:

The instance constant in the room editorNote that this name can be be edited and given a more descriptive name - although the name must be unique to the entire game - and it can be used as the left-hand side of the point:

inst_4DB70D2.speed = 0;

-

By far the most common and practical method, however, is to use a variable on the left of the point, as long as the variable in question has stored a valid instance id. The following examples illustrate this.

+

By far the most common and practical method, however, is to use a variable on the left of the point, as long as the variable in question has stored a valid instance handle. The following examples illustrate this.

// Example 1
var _inst = instance_position(mouse_x, mouse_y, all);
- if (instance_exists(_inst))
+ if (instance_exists(_inst))
{
    _inst.speed = 0;
}
@@ -38,16 +40,21 @@

Addressing Variables In Other Instances

_inst.direction = point_direction(_inst.x, _inst.y, x, y);
_inst.target = id;

-

In the above code for Example 1, there is an instance_exists call in the code block. This is because using the point method to access or change another instances value will give an error and crash the game if the instance does not exist, and there is the possibility that this is the case in that example. We don't need the check however in Examples 2 and 3 because we know that the instance is there since in Example 2 we created it, and in Example 3, its the other instance in a collision event. However, if there is any possibility that the instance could be destroyed, deactivated, or otherwise removed from the room while using this method, you should always check beforehand using the instance_exists function or the instance_number function.

-

Note that you cannot use the special keyword all with this method to target all instances (e.g.: all.val = 10; would give an error), but you can use the keywords other and self without issues. For example, using other in a collision event:

-

// Example 3 other.hp -= 10;
+

Example 1 finds an instance at the mouse position and changes its speed. Example 2 creates a new instance, changes its direction and sets a custom target variable. Both examples target one specific instance using its instance handle.

+

In Example 1, there is an instance_exists call in the code block. This is because using the point method to access or change another instances value will give an error and crash the game if the instance does not exist, and there is the possibility that this is the case in that example.

+

We don't need the check however in Example 2 because we know that the instance is there since we created it. However, if there is any possibility that the instance could be destroyed, deactivated, or otherwise removed from the room while using this method, you should always check beforehand using the instance_exists function.

+

Note that you cannot use the special keyword all with this method to target all instances (e.g.: all.val = 10; would give an error), but you can use the keywords other and self without issues. For example, using other in a collision event to target the instance you collided with:

+

// Example 3
+ other.hp -= 10;
+
if (other.hp <= 0)
{
    other.sprite_index = spr_E_Dead;
- }

+ } +

It is also important to note that you cannot use any function by itself as the left-hand side of an assignment. For example, the following code would give you an error:

instance_nearest(x, y, obj).speed = 0;

-

The return value for the expression in that code example is an integer number (the unique ID value for the nearest instance) and so it must be enclosed in brackets ( ) to be used in this way and properly address the instance required. The above code would be correctly written as:

+

The return value for the expression in that code example is an instance handle (for the nearest instance) and so it must be enclosed in brackets ( ) to be used in this way and properly address the instance required. The above code would be correctly written as:

(instance_nearest(x, y, obj)).speed = 0;

//or
@@ -55,7 +62,7 @@

Addressing Variables In Other Instances

var _inst = instance_nearest(x, y, obj);
_inst.speed = 0;

-

These are all perfectly valid ways of reading, changing and setting variables in other instances, and work because the point is actually an operator. It takes a value as the left operand and a variable as the right operand, and returns the address of this particular variable in the indicated object or instance. All the object names, constants, IDs, etc., simply represent values and these can be dealt with like any other value.

+

These are all perfectly valid ways of reading, changing and setting variables in other instances, and work because the point is actually an operator. It takes a value as the left operand and a variable as the right operand, and returns the address of this particular variable in the indicated object or instance. All the object names, constants, IDs, etc. simply represent values and these can be dealt with like any other value.

The other way to reference variables in another instance is to use the GameMaker Language statement with

// This will affect all instances of the object "obj_Enemy"
with (obj_Enemy)
@@ -65,7 +72,7 @@

Addressing Variables In Other Instances


// This will affect one instance of the object "obj_Enemy"
var _enemy = instance_nearest(x, y, obj_Enemy);
- if (instance_exists(_enemy))
+ if (instance_exists(_enemy))
{
    with (_enemy)
    {
@@ -83,7 +90,7 @@

Addressing Variables In Other Instances

Next: Expressions And Operators
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

with

-

As indicated in the section Addressing Variables in Other Instances, it is possible to read and change the value of variables in instances and structs other than the one currently executing any given code. However, in a number of cases you want to do a lot more than just change a single variable within those other instances, and may want to perform more complex code actions that require multiple functions and lines of code. For example, imagine that you want to move all the instances of a ball object in your game 8 pixels down. You may think that this is achieved simply by the following piece of code:

+

As indicated in the section Addressing Variables in Other Instances, it is possible to read and change the value of variables in instances and structs other than the one currently executing any given code.

+

However, in a number of cases you want to do a lot more than just change a single variable within those other instances, and may want to perform more complex code actions that require multiple functions and lines of code, within the scope of another instance or struct.

+

For example, imagine that you want to move all the instances of a ball object in your game 8 pixels down. You may think that this is achieved simply by the following piece of code:

obj_ball.y = obj_ball.y + 8;

-

But this is not correct, as the right-hand side of the assignment gets the value of the y-coordinate of the first ball and adds 8 to it. Next this new value is set as the y-coordinate of all balls, so the result is that all balls get the same y-coordinate, and even if you use the following:

+

But this is not correct, as the right-hand side of the assignment gets the value of the y coordinate of the first ball and adds 8 to it. Next this new value is set as the y coordinate of all balls, so the result is that all balls get the same y coordinate, and even if you use the following:

obj_ball.y += 8;

-

it will have exactly the same effect because it is simply an abbreviation of the first statement. So how do we achieve something like this? This is why the with statement exists in GML.

+

It will have exactly the same effect because it is simply an abbreviation of the first statement. So how do we achieve something like this? This is why the with statement exists in GML.

Syntax

The with statement takes the form:

-

with (<expression>)
+

with (<expression>)
{
    <statement>;
    <statement>;
    ...
}

-

The expression can take a number of different inputs:

+

The expression can take a number of different inputs:

-

This will then change the scope of the code within the curly brackets { } from the instance, struct or function that executes the with to the instance (or instances or struct) given in the expression.

-

Once the expression has set the scope of the with, the statement will then be executed for each of the indicated instances or structs, as if it is the current (i.e. self). So, returning to our original problem, to move all instances of the ball object 8 pixels down you would type:

+

This will then change the scope of the code within the curly brackets { } from the instance, struct or function that executes the with to the instance (or instances or struct) given in the expression.

+

Once the expression has set the scope of the with, the statement will then be executed for each of the indicated instances or structs, as if it is the current scope (i.e. self). So, returning to our original problem, to move all instances of the ball object 8 pixels down you would type:

with (obj_ball)
{
-     y += 8;
+     y += 8;
}

- +

Since we passed it an object handle (obj_ball), it executes the block code for all instances of that object. If you were to pass a specific instance handle, the code would execute only for that instance.

If you want to execute multiple statements, just include them in the curly brackets, the same as you would around any other code block. So for example, to move all the balls in our example to a random position and give them a random speed and direction, you would use:

with (obj_ball)
{
-     x = random(room_width);
-     y = random(room_height);
-     speed = 1 + random(2);
-     direction = random(360);
+     x = random(room_width);
+     y = random(room_height);
+     speed = 1 + random(2);
+     direction = random(360);
}

-

 

-
-

 

+
+

NOTE Instances in a room are created in a certain order, and their Create events are also executed as they are created one-by-one. This means that you must be careful when running a with() statement on a different instance that has not been created yet, as that will cause the statement to not execute as expected.
+
+ For example: let's say ObjectA is created before ObjectB, and you have the following code in ObjectA's Create event:
+
+ with (ObjectB) myValue = 10;
+
+ ObjectA is created first and its Create event runs, where you would expect it to set the value in ObjectB. However you will instead find that nothing happens. This is because no instances of ObjectB have been created yet, so the with() statement does not execute at all. +

+

With as a Loop

-

The with statement essentially performs a loop. Depending on the result of the expression, the statements inside the curly brackets { } will either be not executed at all, executed a single time or multiple times: 

+

The with statement essentially performs a loop. Depending on the result of the expression, the statements inside the curly brackets { } will either be not executed at all, executed a single time or multiple times:

-

Because with behaves as a loop, you can use the special break and continue statements in it as well. Using break will immediately exit the with code block and move on to any code that is in the event or function after the with should have finished, e.g.:

+

Because with behaves as a loop, you can use the special break and continue statements in it as well. Using break will immediately exit the with code block and move on to any code that is in the event or function after the with should have finished, e.g.:

var _count = 0;
with (obj_enemy)
{
    if (++_count > 10)
    {
-         break;
+         break;
    }
-     hp = 100;
+     hp = 100;
}

The above code loops through the instances in the room of an object obj_enemy and sets the variable hp to 100 for the first 10 it finds. If any more than 10 instances exist, the with code will call break and end.

-

An example of using continue in a with loop would be:

+

An example of using continue in a with loop would be:

with (obj_enemy_parent)
{
    if (invulnerable == true)
@@ -82,32 +90,32 @@

With as a Loop

This code will loop through all instances with the parent obj_enemy_parent, then checks each instance to see if the invulnerable instance variable is true or not. If it is, the continue keyword ends the current iteration of the loop and moves on to the next available instance, otherwise it removes 25 from the hp variable. This will repeat until all instances with that parent have been checked.

Specific Uses

The "other" Instance or Struct

-

As mentioned above, within the statement(s), the indicated instance or struct has become the target (self) instance that runs the code block, which means that the original instance (that contains the with and the entire code block) has become the other instance.

-

So - for example - to move all balls to the position of the current instance that actually contains the code, you can type this:

+

As mentioned above, within the statement(s), the indicated instance or struct has become the target (self) instance that runs the code block, which means that the original instance (that contains the with and the entire code block) has become the other instance.

+

So - for example - to move all balls to the position of the current instance that actually contains the code, you can type this:

with (obj_ball)
{
-     x = other.x;
-     y = other.y;
+     x = other.x;
+     y = other.y;
}

Executing Code in a New Instance

with (instance_create_layer(x, y, "Instances", obj_ball))
{
-     speed = other.speed;
-     direction = other.direction;
+     speed = other.speed;
+     direction = other.direction;
}

The above code will create an instance of obj_ball and assign it the speed and direction of the instance that runs the whole code block.

-

 If you simply need to assign values to the new instance's variables, you can pass them through thevar_struct parameter of instance_create_layer / instance_create_depth.

+

If you simply need to assign values to the new instance's variables, you can pass them through thevar_struct parameter of instance_create_layer / instance_create_depth.

Instance Checking Functions

-

Quite a few instance functions return either an Object Instance or noone. This makes them convenient to use in combination with the with statement: 

+

Quite a few instance functions return either an Object Instance or noone. This makes them convenient to use in combination with the with statement:

with (instance_nearest(x, y, obj_ball))
{
-     instance_destroy();
+     instance_destroy();
}

-

The above code will destroy the instance of obj_ball nearest to the instance running the code. When no instance is found, the function returns noone so that the code inside the with isn't executed.

+

The above code will destroy the instance of obj_ball nearest to the instance running the code. When no instance is found, the function returns noone so that the code inside the with is not executed.

Assigning Struct Variables

-

with(clone_struct)
+

with (clone_struct)
{
-     xx = other.x;
+     xx = other.x;
    yy = other.y;
    spd = other.speed;
    dir = other.direction;
@@ -117,30 +125,34 @@

Local Variable to Cross Scopes

var _inst = noone;
with (obj_ball)
{
-     if (str > other.str)
-     {
+     if (str > other.str)
+     {
        _inst = id;
    }
}
+
if (_inst != noone)
{
-     target = _inst;
- }

-

The above code is slightly more complex than previous ones due to it using a local variable. This variable is local to either the event or the script function and not to the instance or struct and so can be used and accessed by all instances that are referenced within the code block. So, in the code above we have set a local variable to the special keyword noone and then use the with construction to have every instance of obj_ball check their str variable against that of the instance running the code block. If the value of the variable is larger, then they store their unique ID in the inst local variable, meaning that at the end of the code, only the instance with a value greater than the calling instance (or the keyword noone if none are larger) will be stored in the local variable _inst.

+     target = _inst;
+ } +

+

The above code is slightly more complex than previous ones due to it using a local variable. This variable is local to either the event or the script function and not to the instance or struct and so can be used and accessed by all instances that are referenced within the code block. So, in the code above we have set a local variable to the special keyword noone and then use the with construction to have every instance of obj_ball check their str variable against that of the instance running the code block. If the value of the variable is larger, then they store their unique ID in the inst local variable, meaning that at the end of the code, only the instance with a value greater than the calling instance (or the keyword noone if none are larger) will be stored in the local variable _inst.

 

 

-

 

-


-  

-

 

+ + \ No newline at end of file diff --git a/Manual/contents/GameMaker_Language/GML_Overview/Method_Variables.htm b/Manual/contents/GameMaker_Language/GML_Overview/Method_Variables.htm index b55ce5b73..4081443e1 100644 --- a/Manual/contents/GameMaker_Language/GML_Overview/Method_Variables.htm +++ b/Manual/contents/GameMaker_Language/GML_Overview/Method_Variables.htm @@ -14,7 +14,7 @@ -

Method Variables

+

Method Variables

A method variable is essentially a variable that has had a function assigned to it, "binding" the function to an instance and enabling you to use the variable to refer to the function - much like you use a runtime function name to refer to a built-in GML function. The variable used can be local, instance or global in scope (see here for more information on variable scope).

Also see: Script Functions vs. Methods

Creating Methods

@@ -36,7 +36,7 @@

Creating Methods

 To create a function in GML Visual, use Declare A New Function. Enable its "Temp" option to create a method variable (first syntax shown above).

In general, however, you would use the first form for methods, and the second form for defining script functions, since the second form will also assign a script index to the function name while the first form will be a "true" method (and require the use of the global prefix if used to define a scripted function).

-

NOTE You can check this by using both forms in project and then calling the runtime function typeof() on each of them. One will be classed as a "number" - since it returns a script index ID - and the other will be classed as a "method".

+

 You can check this by using both forms in project and then calling the runtime function typeof on each of them. One will be classed as a "number" - since it returns a script index ID - and the other will be classed as a "method".

So, keep in mind that - in general - we will always be referring to functions that have not been defined with a script index when we are talking about methods and method variables. 

Below you can see three simple examples of creating a method variable using different scopes:

// Local
@@ -58,7 +58,7 @@

Creating Methods

}

Notice that in the above code, the various parameters that are given as inputs for the function are all named and these names are what should be used within the function to refer to the different inputs. Also note that you can use the return statement to return a value from a function for use elsewhere in your code, and that a function with no return value defined, will return undefined.by default.

-

NOTE While the variable will be in the chosen scope, the actual function will be bound to the scope that it was initially defined in. For example, script functions are all global scope and "unbound" (ie: they are not associated with any instances), but if you have a script function that creates another function as a method variable within it and then you call this script function from an instance, the function used within the script will be bound to the instance variable as a method. In general this is not something you ever need to think about but for more complex operations with method variables it's worth taking into consideration. This also applies when using other constructs like with - when you create a method variable inside a with, the function will be bound to the instance that is currently in scope.

+

 While the variable will be in the chosen scope, the actual function will be bound to the scope that it was initially defined in. For example, script functions are all global scope and "unbound" (ie: they are not associated with any instances), but if you have a script function that creates another function as a method variable within it and then you call this script function from an instance, the function used within the script will be bound to the instance variable as a method. In general this is not something you ever need to think about but for more complex operations with method variables it's worth taking into consideration. This also applies when using other constructs like with - when you create a method variable inside a with, the function will be bound to the instance that is currently in scope.

Once created, the method variable can be used just as you would a runtime function or a script function, for example:

create_vec = function(_x1, _y1, _x2, _y2);
{
@@ -97,7 +97,7 @@

Creating Methods

Next: Script Functions vs. Methods
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

Struct Forbidden Variables

-

When creating a struct, it is possible to use certain built-in variables as member variable names, for example:

-

mystruct =
- {
-     object_index : obj_Player,
-     speed : 3,
-     image_blend : c_red
- }

-

However, only local and instance scope built-in variables can be used this way and assigned values as if they were regular struct member variables. Using global scope built-in variables is forbidden and will cause issues with your game. Below you can find a full list of these variables so that you know which ones to avoid.

-

The following built-in global variables are all available for use in your projects but cannot be used as struct member variables:

- -

 

-

Apart from those global variables, there are also a number of obsolete built-in global variables that are unavailable due to the possibility of them being included in imported legacy products (GameMaker needs to reserve these variables so it can recognise them on import and flag them to be updated/removed):

- +

No forbidden names anymore, you may use any names you like - even weird ones.

 

 

-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

Constants

A constant is a type of variable that is set once at the start of the game and then never changes. In fact, constant values cannot be changed after they have been declared. This makes them ideal for holding values that are used throughout the game to identify special data.

-

In the GameMaker Language there are two types of user-defined constants: macros and enums, both of which are explained below. Also note that any value that is always the same is classed as a constant, regardless of the data type, for example, a string or the number 3.

-

 The GameMaker Language also has a number of built-in constant values that are used to identify specific things. These are outlined on the appropriate pages for the runtime functions that require them in the GML Reference section.

+

In the GameMaker Language there are two types of user-defined constants: enums and macros, both of which are explained below. Also note that any value that is always the same is classed as a constant, regardless of the data type, for example, a string or the number 3.

+

 The GameMaker Language also has a number of built-in constant values that are used to identify specific things. These are outlined on the appropriate pages for the runtime functions that require them in the GML Code Reference section and some general ones are mentioned at the bottom of this page.

+

Enums

+

An enum is an "enumerator"; it essentially permits you to create your own limited data type with a list of constant values. They have the following structure:

+

enum <NAME>
+ {
+     <MEMBER> [= <VALUE>],
+     <MEMBER> [= <VALUE>],
+     // etc...
+ } +

+

In the following example, we create an enum for the colours of the rainbow and assign it various constants and default values:

+

enum RAINBOW
+ {
+     RED,
+     ORANGE,
+     YELLOW,
+     GREEN,
+     BLUE,
+     INDIGO,
+     VIOLET
+ }

+

The enum entries can only be integer numbers or expressions with previous enums that evaluate to an integer number, and by default are numbered from 0 upwards, so our example given above would default to RED = 0, ORANGE = 1, YELLOW = 2, etc...

+

You can also assign custom values to the enum variables at the time of creation:

+

enum ENUM_TEST
+ {
+     VAL = 10
+ }
+
+ enum RAINBOW
+ {
+     RED = 5,
+     ORANGE = 5 * 2,
+     YELLOW = 15,
+     GREEN = 20,
+     BLUE = 25,
+     INDIGO = 30,
+     VIOLET = 35 * ENUM_TEST.VAL
+ } +

+

Notice in the above example we use another enum to create an expression for "VIOLET". This only works if the enum being referenced was created before the enum that is using it in an expression, but it will not work for variables or functions, since the enum value must be able to be evaluated as a constant when the project is Compiling.

+

Also note that all enum values evaluate to integer values, and when you create your own you should be aware that only integer values are permitted for enums to work. This value can be any integer number that a floating point double precision number can represent, including negative values.

+

To later access the value within a given enum type, use the point "." method, like this:

+

variable = <ENUM_NAME>.<ENUM_MEMBER>;

+

As an example, let's use the "RAINBOW" enum that we created in the code above:

+

colour_value = RAINBOW.GREEN * RAINBOW.RED;

+

The colour_value variable would now hold the value 100 (20 * 5).

+

 You cannot modify the values for any enum constant after it has been created.

+

 Enum values are stored as int64s, so running is_real on them will return false.

Macros

-

While not exactly variables, macros are similar to them in how they are used, i.e.: they are named values that you can use throughout your code to replace hard-coded values. Basically, a macro is a named variable that holds an expression. You can define your own macros using the Script Editor and then use them in your code and actions as if they were regular variables, with the one difference being that they can't be changed in the game.

+

A macro is a global identifier that holds an expression (which may be just a value).

+

You can see it as being similar to a variable, as it can hold any type of value (e.g. 10, "hello world", etc.). The main difference is that a macro cannot be changed at runtime once it's defined, as it needs to have a known value when your game is Compiling.

+

In addition to that, a macro can be an expression (e.g. sin(current_time) + 10), which can then be used on its own in a statement, or as part of a larger expression. This does mean that the use of such a macro will not always be constant, as any function calls or identifiers included in the macro may return different values at different points in time in your game.

+

Syntax

The syntax structure for a macro is as follows:

#macro <NAME> <VALUE>

For example, say you define the following macro "TOTAL_WEAPONS":

@@ -27,13 +77,13 @@

Macros

Macro syntax...

The syntax shown above must be used correctly to define macros. You cannot use an equal sign (like in variables) or put a semicolon at the end (like in a regular statement). Doing so will cause your macro definition to become invalid.

- For example, this is not the correct way to define a macro:
+ For example, this is not a correct way to define a macro:

#macro TOTAL_WEAPONS = 10;

Removing the equal sign and colon will make it a valid macro definition.

-  The recommended GML naming conventions recommend UPPERCASE_NAMING for constants, however you can use lower case or any other naming conventions you like. +  The recommended GML naming conventions recommend UPPERCASE_NAMING for constants, however you may use lower case or any other naming conventions you like.

You could then use this in your code like this:

pos++;
@@ -43,15 +93,17 @@

Macros

    pos = 0;
}

+

This may be in any object or script in your game, as a macro is global and can be used from anywhere.

Note that you would not be able to change the constant's value, so code like this will cause the game to crash:

TOTAL_WEAPONS = 11;

You can define a macro anywhere in your code or in a script and it will be pre-compiled and included in your game as if it was there from the start, but we recommend that you create a dedicated script asset and define all your macros in there. It will be easier to organise and debug later!

Expression As Macro

-

If you need the value of a macro to change at run-time then you should probably make it a global variable, since these can be changed from code during a game, unless you set the macro to be a runtime function or any expression. By setting the macro to a function/expression it means that this function/expression will be called every time you use the macro. For example:

+

As previously mentioned, a macro has the capability of holding an expression. This means if there's a function that you have to repeatedly call in your game with the same parameters, you can make it a macro:

#macro COL make_colour_hsv(irandom(255), 255, 255)

You would then call this macro something like this:

image_blend = COL;

-

Using this code will make the image blend a different colour every time the macro is used. It is worth noting that you can also split macros over multiple lines using the \ character to show where the line breaks are. An example would be something like:

+

Using this code will make the image blend a different colour every time the macro is used.

+

You can also split macros over multiple lines using the \ character to show where the line breaks are. An example would be something like:

#macro HELLO show_debug_message("Hello" + \
string(player_name) + \
", how are you today?");

@@ -67,52 +119,6 @@

Configuration Override

As you can see, you give the config name first then a colon : and then the macro name and override value. Note that you cannot have any white-space between the colon : and either the config name nor the macro name otherwise you will get an error.

Macro overrides are inherited by child configurations. Say you have the following configuration set-up:

Here, any macro overrides set for MobileAds will be inherited by MobileNoAds, and you can override an inherited value by setting a macro for that child configuration.

-

Enums

-

An enum is an "enumerator"; it essentially permits you to create your own limited data type with a list of constant values. They have the following structure:

-

enum <NAME>
- {
-     <MEMBER> [= <VALUE>],
-     <MEMBER> [= <VALUE>],
-     // etc...
- } -

-

In the following example, we create an enum for the colours of the rainbow and assign it various constants and default values:

-

enum RAINBOW
- {
-     RED,
-     ORANGE,
-     YELLOW,
-     GREEN,
-     BLUE,
-     INDIGO,
-     VIOLET
- }

-

The enum entries can only be integer numbers or expressions with previous enums that evaluate to an integer number, and by default are numbered from 0 upwards, so our example given above would default to RED = 0, ORANGE = 1, YELLOW = 2, etc...

-

You can also assign values to the enum variables at the time of creation:

-

enum ENUM_TEST
- {
-     VAL = 10
- }
-
- enum RAINBOW
- {
-     RED = 5,
-     ORANGE = 5 * 2,
-     YELLOW = 15,
-     GREEN = 20,
-     BLUE = 25,
-     INDIGO = 30,
-     VIOLET = 35 * ENUM_TEST.VAL
- } -

-

Notice in the above example we use another enum to create an expression for "VIOLET". This only works if the enum being referenced was created before the enum that is using it in an expression, but it will not work for variables or functions, since the enum value must be able to be evaluated as a constant when the project is Compiling. Also note that all enum values evaluate to integer values, and when you create your own you should be aware that only integer values are permitted for enums to work. This value can be any integer number that a floating point double precision number can represent, including negative values.

-

To later access the value within a given enum type, you can use the point "." method, like this:

-

variable = <ENUM_NAME>.<ENUM_MEMBER>;

-

As an example, let's use the "RAINBOW" enum that we created in the code above:

-

colour_value = RAINBOW.GREEN * RAINBOW.RED;

-

The colour_value variable would now hold the value 100 (20 * 5).

-

 You cannot modify the values for any enum constant after it has been created, much the same as you can't modify macros after they have been created.

-

 Enum values are stored as int64s, so running is_real on them will return false.

Built-In Constants

The following table shows a list of the built-in constants that can be returned by some functions and operations in your projects:

@@ -169,7 +175,7 @@

Built-In Constants

Next: Local Variables
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

audio_get_type

-

When adding audio to GameMaker it can be either streamed or in memory. If you need to know whether a given sound index is for streamed audio or not you can use this function which will return 1 for streamed, 0 for sound in memory, and -1 if there is any error or the index does not point to a valid sound resource.

+

When adding audio to GameMaker it can be either streamed or in memory. If you need to know whether a given sound index is for streamed audio or not you can use this function which will return 1 for streamed, 0 for sound in memory, and will throw a fatal error if the index does not point to a valid sound resource.

 

Syntax:

audio_get_type(index);

diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_play_sound.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_play_sound.htm index 7cf7ed622..21ef3a349 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_play_sound.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_play_sound.htm @@ -54,7 +54,7 @@

Syntax:

- + @@ -73,14 +73,14 @@

Returns:

Sound Instance ID

 

Example 1: Basic Use

-

if (health <= 0)
+

if (health <= 0)
{
    lives -= 1;
    audio_play_sound(snd_PlayerDead, 10, false);
}

The above code checks the "health" global variable and if it is less than or equal to 0, it will remove 1 from the "lives" global variable and play a sound.

Example 2: Optional Properties

-

if (bbox_left > room_width)
+

if (bbox_left > room_width)
{
    audio_play_sound(snd_Goodbye, 10, false, 1.1, 0, 2);
}

@@ -103,7 +103,7 @@

Example 3: Asset & Instance Properties

Next: audio_play_sound_ext
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

audio_sound_get_asset

-

This function returns the Sound Asset that was used to play the given Sound Instance ID. The sound must be active (i.e. currently playing) for this function to return the correct value, otherwise it will return undefined.

+

This function returns the Sound Asset that was used to play the given Sound Instance ID. The sound must be active (i.e. currently playing) for this function to return the correct value, otherwise it will throw a fatal error.

 

Syntax:

audio_sound_get_asset(index);

diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_track_position.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_track_position.htm index 9604958d3..8253fa8d0 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_track_position.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_track_position.htm @@ -17,10 +17,10 @@

audio_sound_get_track_position

This function gets the position (in seconds) within the sound file for the sound to play from.

-

The function can take a Sound Asset or a sound instance. It returns: 

+

The function can take a Sound Asset or a Sound Instance ID. It returns: 

 

Syntax:

@@ -58,7 +58,7 @@

Example 1:

Next: audio_sound_set_listener_mask
-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

instance_activate_object

-

With this function you can activate a single instance or all instances of a specific object from all those that have been deactivated previously. Note that if you have deactivated an instance or object that has been flagged as Persistent, then - you will need to reactivate it again with this function before changing room, otherwise it will not be carried over and will be discarded instead. Note too that activation is not instantaneous, and an instance that has been activated in this - way will not be considered to be active until the end of the event in which the function was called.

+

With this function you can activate a single instance or all instances of a specific object from all those that have been deactivated previously. Note that if you have deactivated an instance or object that has been flagged as Persistent, then you will need to reactivate it again with this function before changing room, otherwise it will not be carried over and will be discarded instead. Note too that activation is not instantaneous, and an instance that has been activated in this way will not be considered to be active until the end of the event in which the function was called.

 

Syntax:

instance_activate_object(obj);

offset Real  The time (in seconds) to start playing. Values beyond the end of the sound are clamped to its length. The default value is the asset-level offset, this value overrides it when provided.  The time (in seconds) to start playing. Values beyond the end of the sound are clamped to its length. The default value is the asset-level offset.
pitch
- + + - + - + + - +
ArgumentTypeArgumentType Description
objobjObject Asset or Object Instance The object or instance to activate (the keyword all can also be used).

 

Returns:

-

+

N/A

 

Example:

-

instance_activate_all();
var _vx = camera_get_view_x(view_camera[0]);
var _vy = camera_get_view_y(view_camera[0]);
var _vw = camera_get_view_width(view_camera[0]);
var _vh = camera_get_view_height(view_camera[0]);
instance_deactivate_region(_vx - - 64, _vy - 64, _vw + 128, _vh + 128, false, false);
instance_activate_object(obj_Lights); -

+

instance_activate_all();
+ var _vx = camera_get_view_x(view_camera[0]);
+ var _vy = camera_get_view_y(view_camera[0]);
+ var _vw = camera_get_view_width(view_camera[0]);
+ var _vh = camera_get_view_height(view_camera[0]);
+ instance_deactivate_region(_vx - 64, _vy - 64, _vw + 128, _vh + 128, false, false);
+ instance_activate_object(obj_Lights);

The above code activates all instances within the room and then deactivates those that are outside of the limits of the current camera view, except for the object "obj_Lights" which are re-activated again at the end.

 

 

@@ -53,7 +57,7 @@

Example:

Next: instance_activate_region
-
© Copyright YoYo Games Ltd. 2021 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

visible

-

An instance can be flagged as visible or not by setting this variable to true (visible) or false (invisible). This works by telling GameMaker to skip the draw event for this instance, so care must be taken when using this as it means that no code placed in the draw event will be run while the instance is not visible. Also note that if the layer that the instance is assigned to is flagged as invisible, setting this variable to true will have no effect until the layer itself is flagged as visible too.

+

An instance can be flagged as visible or not by setting this variable to true (visible) or false (invisible).

+

This works by telling GameMaker to skip the draw event for this instance, so care must be taken when using this as it means that no code placed in the draw event will be run while the instance is not visible. Also note that if the layer that the instance is assigned to is flagged as invisible, setting this variable to true will have no effect until the layer itself is flagged as visible too.

+

 During Draw events, this variable will become read-only and attempting to change it will throw a fatal error.

 

Syntax:

visible

 

Returns:

-

Boolean

+

Boolean

 

Example:

-

if (other.visible == true)
+

if (other.visible == true)
{
    x = xprevious;
    y = yprevious;
}

-

The above code will check the visible flag of the "other" instance in a collision event and if it is set to true move that instance back to its previous position.

+

The above code will check the visible flag of the "other" instance in a collision event and if it is set to true, it will move the current instance back to its previous position.

 

 

-
© Copyright YoYo Games Ltd. 2023 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

event_inherited

-

This function will call the current event of the parent object of the instance. Normally, when an instance has a parent object, it automatically inherits all the same events as the parent, but if (for example) your parent object has a create event and you add one to your child object, all instances of the child object will run the new create event that you have added and not that which is in the parent object. Should you need to use both the parent object event and the child object event of the same type, you should use this function as it will run the parent object event before continuing with the rest of the code or actions that the child event contains.

+

This function calls the parent object's version of the current event. For example, if you call this in the Step event of obj_B which is a child of obj_A, obj_A's Step event will be called as a result of this function. As such you cannot call this function outside of an object's event as it would be of no use anywhere else.

+

Normally, when an instance has a parent object, it automatically inherits all the same events as the parent, but if (for example) your parent object has a Create event and you add one to your child object choosing to override the parent's event, all instances of the child object will run the new Create event that you have added and not that which is in the parent object. Should you need to use both the parent event and the child event of the same type, you should use this function as it will run the parent object event before continuing with the rest of the code or actions that the child event contains.

 

Syntax:

event_inherited();

 

Returns:

-

+

N/A

 

Example:

event_inherited();
@@ -42,7 +43,7 @@

Example:

Next: event_perform
-
© Copyright YoYo Games Ltd. 2021 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

Objects

-

In GameMaker you have objects and you have instances. Objects are essentially the base template for an instance, and as such are never present in a room directly... Only instances of the object are placed in the room. This means that if you want to change something for all instances you are going to create, then you can do it by changing the object.

+

In GameMaker you have objects and you have instances. Objects are essentially the base template for an instance, and as such are never present in a room directly... Only instances of the object are placed in the room. This means that if you want to change something for all instances you are going to create in the future, then you can do it by changing the object.

 Changing anything about an object will not change any instances currently present in the room, only those that are created after the change.

+

 See the Objects vs. Instances page for information regarding the differences between using object and instance handles.

You can also access information about a base object and use it to dictate behaviours or changes in the game. For example, you can do a check for a parent object ID, and in the following code if an instance with that parent is found you can then check its object_index to decide what should be done.

GameMaker gives you a number of functions that permit you to get various details about an object. Note, an object is not an instance (an in-game entity), it is purely a resource from which all instances are created. This means that the return values of these functions may be different to the actual values shown by instances in the room, as once an instance is created it can be changed through code and GML Visual actions.

-

 

 

There are also a number of functions that permit you set the properties for an object. It should be noted that any instances of this object that already exist in the room may not be affected by these functions, but all new instances of this object created in the room will be, so it is recommend that you never change an objects properties when instances of that object are present in the current room.

-