From 18dd859d692dfc281128e328b7cb8f37335da3bc Mon Sep 17 00:00:00 2001
From: gurpreetsinghmatharoo Script assets are essentially a collection of one or more user-defined functions or variables that you write yourself as snippets of code in The Script Editor. The functions you define in a script can resolve expressions, return values or do anything else that the GameMaker Language permits, just like the built-in Runtime Functions. Script functions should generally be used if you have a block of code that you use in more than one place or object, or when you want a block of code to be used across multiple objects in a modular fashion. Using scripts to define functions means that you can change the function just once when required and the change will be "picked up" by every object that has a call to the function. Scripts can also be very handy from an organisational point of view, as they permit you to create groups of functions that belong to a certain category - for example, you might have several functions all related to collisions between instances in your game, so you would create a "Collision_Functions" script and store all these functions together in it. Scripts can also be very handy from an organisational point of view, as they permit you to create groups of functions that belong to a certain category - for example, you might have several functions all related to collisions between instances in your game, so you would create a Collision_Functions script and store all these functions together in it. When creating a Script Asset with functions in it, the functions can be created using the following formats: function name( parameter1, parameter2, ... ) To create a function in GML Visual, use Declare A New Function. Enable its "Temp" option to create a method variable (second syntax shown above). In general, however, you would use the first form for script functions as it will define the function as specifically being a script function, meaning that it will be global in scope, be assigned a script index, and not require the global prefix to identify it since the compiler will recognise it as a script function. Using the second form will instead generate a global scope method variable, and as such it will not be recognised as a script function by the IDE and will require the use of the global prefix when being referenced in your code. Related: Script Functions vs. Methods You can check this by using both forms in a script and then calling the runtime function typeof() on each of them. One will be classed as a "ref" - since it returns a script function reference - and the other will be classed as a "method". Using the second form will instead generate a global scope method variable, and as such it will not be recognised as a script function by the IDE and will require the use of the global prefix when being referenced in your code. Related: Script Functions vs. Methods You can check this by using both forms in a script and then calling the runtime function typeof on each of them. One will be classed as a "ref" - since it returns a script function reference - and the other will be classed as a "method". This rule also applies when a function or method is created in an Object's event, however in that case the created script function (with the first syntax) will not be global and will only be available in the instance's context. See Method Variables for more information. You can define your own parameters/arguments for a function, which will be available to the function as local variables and can be used for any purpose within that function:debug_event
Script Functions And Variables
Creating Functions
@@ -37,8 +37,8 @@ Creating Functions
Parameters/Arguments
Parameters/Arguments
speed = spd;
direction = dir;
}
This function takes two arguments and applies their values to the instance's speed and direction variables. It can now be called like any runtime function and arguments can be passed into it:
+This function takes two arguments and applies their values to the instance's speed and direction variables. It can now be called like any runtime function and arguments can be passed into it:
var _mouse_dir = point_direction(x, y, mouse_x, mouse_y);
move(4, _mouse_dir);
Arguments passed into a function can also be accessed through the argumentN variables (argument0, argument1, etc.) or the argument[] array (argument[0], argument[1], etc.).
-You can get the number of arguments passed into the function using argument_count, thus allowing a variable number of arguments to be passed in.
-function print(){
+
Arguments passed into a function can also be accessed through the argumentN variables (argument0, argument1, etc.) or the argument[] array (argument[0], argument[1], etc.).
+You can get the number of arguments passed into the function using argument_count, thus allowing a variable number of arguments to be passed in.
+function print()
+ {
var _str = "";
for (var i = 0; i < argument_count; i ++)
@@ -72,17 +73,17 @@
This print() function loops through all the passed arguments, and adds them to a string variable. That string is then printed to the output log.
You can now call this function with as many strings as you like, which will all be joined together.
If an argument is not given to a function, its value will be undefined. You can use this to define optional arguments, and check whether an argument is passed in or not by checking if it is equal to undefined. However, you can also explicitly define a default value for an argument which will be used instead of undefined when it is not passed in.
+If an argument is not given to a function, its value will be undefined. You can use this to define optional arguments, and check whether an argument is passed in or not by checking if it is equal to undefined. However, you can also explicitly define a default value for an argument which will be used instead of undefined when it is not passed in.
You can assign such a default value to a parameter using the equal (=) sign, making it an optional variable:
function move(spd, dir = 90)
{
speed = spd;
direction = dir;
}
If the dir argument is not passed in when calling the above function, then its value will default to 90, moving the instance in an upward direction.
- You can omit arguments from function calls and they will default to undefined (or the default value for that argument as defined by the function).
+
If the dir argument is not passed in when calling the above function, then its value will default to 90, moving the instance in an upward direction.
+ You can omit arguments from function calls and they will default to undefined (or the default value for that argument as defined by the function).
- For example, writing my_func(0,,,1) is the same as writing my_func(0, undefined, undefined, 1).
+ For example, writing my_func(0,,,1) is the same as writing my_func(0, undefined, undefined, 1).
The default value of an optional variable can be an expression. When defining such a default value, you can call functions, use variables of any types and do anything you otherwise can in an expression in GML Code.
@@ -116,7 +117,7 @@Additional functions for the script can be added using the same format as shown above, one after the other within the script asset.

Functions in scripts can also return a value, just as runtime functions can, and as such they can be used in expressions. For this you would use the return statement:
+Functions in scripts can also return a value, just as runtime functions can, and as such they can be used in expressions. For this you would use the return statement:
return <expression>;
It should be noted that the execution of the function ends at the return statement, meaning that any code which comes after return has been called will not be run. Here is a short example function from a function called "sqr_calc" which calculates the square of whatever value is passed to it, and in case the given value is not a real number, it uses return to end the function early so the actual calculation never runs:
/// @function sqr_calc(val);
@@ -133,7 +134,7 @@
Note that if you create a script function with no return value then in your code check for one, you will get the value undefined by default.
+Note that if you create a script function with no return value then in your code check for one, you will get the value undefined by default.
To call a script function from within a piece of code, just use it the same way as when calling any runtime function - that is, write the function name with the parameter values in parentheses. So, the above script would be called like this:
if (keyboard_check_pressed(vk_enter))
{
@@ -141,7 +142,7 @@
When using your own functions from scripts in the code editor, you can press
or click the middle mouse button
on the function name to open the script that contains it for editing directly.
It is important to understand that script names are independent of the functions that they contain, so you can name your scripts in a more "common sense" way, i.e.: all your AI functions could go in a script "Enemy_AI" and contain functions like ai_target_pos(), ai_alert_level(), ai_state(), etc.
+It is important to understand that script names are independent of the functions that they contain, so you can name your scripts in a more "common sense" way, i.e.: all your AI functions could go in a script Enemy_AI and contain functions like ai_target_pos(), ai_alert_level(), ai_state(), etc.
However, you can still name a script the same as a function that you define in it and call the script, e.g. if you want one function per script (which can be useful for making reusable libraries so all functions are shown in the Asset Browser). When doing this, it is important to understand how script references behave to avoid code errors, due to the way GameMaker stores asset references.
For example, consider this code, called from an instance's event:
function indirectCall(func, arg)
@@ -186,9 +187,9 @@
In the above case, not only have we defined the functions Foo and Bar but also the variable blah and all of them are considered to have been created in the global scope. The functions don't need the global keyword to be recognised as the compiler understands that these functions are part of the script, but if you wanted to access blah then you would need to do:
+In the above case, not only have we defined the functions Foo and Bar but also the variable blah and all of them are considered to have been created in the global scope. The functions don't need the global keyword to be recognised as the compiler understands that these functions are part of the script, but if you wanted to access blah then you would need to do:
val = global.blah;
-That said, we recommend that you always explicitly type global variables when creating them in scripts to prevent any issues later. Scripts are also an ideal place to define any Macros or Enums (constants), as adding them to a script outside of a function also means that they will be created for use before the game code actually starts running. Below is an example of a script that is creating different global scope values for a game:
+That said, we recommend that you always explicitly type global variables when creating them in scripts to prevent any issues later. Scripts are also an ideal place to define any Macros or Enums (Constants), as adding them to a script outside of a function also means that they will be created for use before the game code actually starts running. Below is an example of a script that is creating different global scope values for a game:
/// Initialise All Global Scope Values And Constants
global.player_score = 0;
global.player_hp = 100;
@@ -224,19 +225,18 @@
So, scripts can be used to generate macros, enums and global variables before the game starts so they are ready for use at any time, and they can also be used to create "unbound" methods (user-defined functions) that can be used in your game like GML runtime functions.
-One final thing to note about script functions is that if you are developing for Web (i.e.: targeting HTML5), then there is an additional function protocol that you can use when adding functions to scripts, which is to prefix a function name with gmcallback_, for example:
+One final thing to note about script functions is that if you are developing for Web (i.e.: targeting HTML5), then there is an additional function protocol that you can use when adding functions to scripts, which is to prefix a function name with gmcallback_, for example:
gmcallback_create_button
-Using the above function name would mean that the function gmcallback_create_button() will not be obfuscated and so can be used in JavaScript extensions and other areas of your game, for example, when using the clickable_* functions.
+Using the above function name would mean that the function gmcallback_create_button() will not be obfuscated and so can be used in JavaScript extensions and other areas of your game, for example, when using the clickable_* functions.
Functions can also make use of static variables, which maintain their values throughout every function call. Please read this page for more information.
-+
Functions can also make use of static variables, which maintain their values throughout every function call. Please read Static Variables for more information.
-
With this function you can poll the window (or tab) state and if it loses focus the function will return false, otherwise it will return true. In most cases you can simply use the os_is_paused function to test this, but in some very specific cases (for example games on Chrome Apps) that function will not trigger, in which case you should use this function instead.
-This function is only valid on the HTML5, Windows, and macOS platforms.
+This function is only valid on the HTML5, GX.games, Windows, and macOS platforms.
window_has_focus()
From f28f0b596ef3f76043f452b6870f8285fd07ad08 Mon Sep 17 00:00:00 2001 From: YYBartTThe following unary operators are provided:
This is an asynchronous function, and as such GameMaker does not block the device it is being run on while waiting for an answer, but rather keeps on running events as normal. Once the user has input the details and pressed the Okay button, an asynchronous Dialog event is triggered which, for the duration of that event only, will have a DS Map stored in the variable async_load.
This map will contain the keys "id", "status", "username" and "password", with the user input stored in "username" and "password".
This function will return an index number for the async event that was triggered, which can then be checked in the corresponding event so that you can "target" specific data in case you're expecting more than one async event to be triggered (perhaps from some other function).
-This function is not supported on the GX.games target.
The password is returned unencrypted. You should make sure to encrypt it before doing anything with it, e.g. saving it to disk, sending it over a network, ...
From db1544abd693a4175b8c40d3f816bda3bf098827 Mon Sep 17 00:00:00 2001 From: gurpreetsinghmatharoo

The Package Manager lets you install packages that GameMaker can use for the IDE and during your game's compilation. Currently you can use this to install latest versions of Localisation plugins, Project Tool and the Prefab Library. This is also used for packages that are required for GMRT (GameMaker Runtime).
+The Package Manager lets you install packages that GameMaker can use for the IDE and during your game's compilation. Currently you can use this to install and manage versions of various IDE features like localisation plugins, Project Tool and the Prefab Library. This is also used for packages that are required for GMRT (GameMaker Runtime).
The list on the left will show you all packages from the selected source, and clicking on a package will show its information on the right, where you can choose a version for the package and install it.
Right-clicking on a package brings up a menu with options:
You can enable or disable update notifications as well as automatic updates for the given package. Note that notifications are enabled by default for GMRT packages and disabled for all other packages.
Some packages may have other packages installed as dependencies. On uninstalling a package, depending on the package, it may or may not uninstall its dependencies or it may prompt the user to choose whether dependencies should be deleted or kept.
-You cannot uninstall a package if another installed package uses it as a dependency.
+You cannot uninstall a package if another installed package uses it as a dependency or if it is a required package for the IDE (e.g. Filters and Effects).
In the top-left corner you can search for a package, and in the top-right corner you can change the source for the packages from a drop-down menu.
A package source is a URL to a remote registry where packages are stored. Selecting a source will change what packages you see listed in the Package Manager, depending not only on the URL of the registry but also on the scopes of that source, which acts as a filter, so only those packages matching the scopes are shown.
diff --git a/Manual/contents/IDE_Tools/Prefab_Library.htm b/Manual/contents/IDE_Tools/Prefab_Library.htm index 8991272f1..b727cb211 100644 --- a/Manual/contents/IDE_Tools/Prefab_Library.htm +++ b/Manual/contents/IDE_Tools/Prefab_Library.htm @@ -106,6 +106,7 @@Currently you can use the official GameMaker Asset Bundles via the Prefab Library.
Open the Prefab Library via the Windows menu in the menu bar. When you open this for the first time, your Prefab Library will be empty.
+You may see Prefab Collections installed by default that are needed for IDE functionality (e.g. Filters and Effects).
Click on "Package Manager" to add Collection packages:
This opens the Package Manager window with the "Package source" drop-down set to "Prefabs". From here, you can install any of the official GameMaker Asset Bundles.
Once installed, they will show up in your Prefab Library, from where you can navigate to any individual assets within the Collections:
From c2e9716be20ad88dae40c5beeefb1f4cd0e9938d Mon Sep 17 00:00:00 2001 From: Gurpreet Singh MatharooWhen you click on the Variable Definitions button it will open up the Object Variables window, which you can then use to generate any number of variables before the Create Event is run for every new instance of the object:
In this window you can click on the button Add to add a new variable to the list. You can then name the variable as well as set its type and adjust its properties:
The variable name must start with a letter and can contain only letters, numbers, and the underscore symbol _ with a maximum length of 64 symbols. So, valid variables are things like fish, foo_bar, num1, and invalid variables would be 6fish, foo bar, or *num. Once you have given the name of the variable you need to set its type, which can be any of the following:
It is worth noting that this feature is particularly useful when working with parent/child objects - since you can have a parent object with a set of defined variables and then simply modify them in a child object (see the section Object Variables And Child Objects below for more details) - and for when you add instances to The Room Editor (see the section on Layers > Instance Layer), since you can also modify these variables for individual instances that have been placed in the room.
The variable name must start with a letter and can contain only letters, numbers, and the underscore symbol _ with a maximum length of 64 symbols. So, valid variables are things like fish, foo_bar, num1, and invalid variables would be 6fish, foo bar, or *num.
You can click the
icon next to a variable's name to define its label and description. This label and description will appear when you hover over the
icon in the Variables window.
Once you have given the name of the variable you need to set its type, which can be any of the following:
This feature is particularly useful when working with parent/child objects - since you can have a parent object with a set of defined variables and then simply modify them in a child object (see the section Object Variables And Child Objects below for more details) - and for when you add instances to The Room Editor (see the section on Layers > Instance Layer), since you can also modify these variables for individual instances that have been placed in the room.
The different types of variable that you can create are listed below:
When you check this you can then input a start value and an end value and instead of having a fixed value shown for the variable in the Object Variables window, you will have a slider that is clamped to these values:This variable can be used to get and to set the persistent flag for the current room. If set to true the room is considered persistent, in which case each time you leave the room and come back again the state of the instances within that room will have been maintained. However if it is flagged as false, each time you return to the room it will be reset to its initial state. You should note that a persistent room uses considerably more memory than a normal room and it is not recommended to have too many of them in your game.
+This variable can be used to get and to set the persistent flag for the current room.
+If set to true the room is considered persistent, in which case each time you leave the room and come back again the state of the instances within that room will have been maintained. However, if it is flagged as false, each time you return to the room it will be reset to its initial state.
+A persistent room uses considerably more memory than a normal room and it is not recommended to have too many of them in your game.
room_persistent;
+room_persistent
if (lives < 1)
+
if (lives < 1)
{
room_persistent = false;
room_goto(rm_start);
}
The above code checks the variable "lives" and if it is less than 1, it will set the room persistence to false and then change rooms.
+The above code checks the variable lives and if it is less than 1, it will set the room persistence to false and then change rooms.
-
The Asset Browser Preferences are used to define certain properties for how the Asset Browser and its elements function. The main options are:
The Asset Browser Preferences are used to define certain properties for how The Asset Browser and its elements function. The main options are:
@@ -67,7 +67,7 @@