0% found this document useful (0 votes)
5 views18 pages

GML Manual

GML (Game Maker Language) is an interpreted programming language developed to complement the game development application Game Maker. The language is based on C++ but is more flexible and does not require strict syntax. GML allows the creation of global and local functions and variables to provide additional functionality to the games created in Game Maker.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views18 pages

GML Manual

GML (Game Maker Language) is an interpreted programming language developed to complement the game development application Game Maker. The language is based on C++ but is more flexible and does not require strict syntax. GML allows the creation of global and local functions and variables to provide additional functionality to the games created in Game Maker.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

GML

Game Maker Language


Game Maker Language (GML) is aprogramming languageinterpreted (although with the
The use of YoYoCompiler can be compiled) developed to be used as a complement of
the game development applicationGame Maker. The language is used in the program
to give greater enhancement to the development of games or other systems within it. The language
it was encoded using the languagesDelphiyC++.
It is aprogramming languagevery flexible, based onC++, although it is also seen
influenced by the syntax of other languages such asPascal. The general structure of the code
GML can take different forms of syntax, as it is not subject to strict syntax.
like that ofC. It is capable of working with numbers, strings, and others in a way
native.

Index
[hide]

1General Syntax
o1.1Functions
o1.2Variables
. 1.2.1Types
. 1.2.2Scope

General syntax[edit]
The languageGMLin terms of syntax it is similar toC++, nevertheless, this language consists of
a lot of flexibility due to its various syntax variations (all of which are valid).
For example, when working with operators, it can work like this:

g=g+1;

But inGMLit is also valid in this way:

g+=1;

This rule of operators can also be applied in/=, -= y*=.


The languageGMLFurthermore, it does not require the mandatory use of the symbol ';' at the end of each line.
or function, which makes it flexible in the strict aspect of syntax.
Functions[edit]
The languageGMLfor understanding already has a large number of functions and systems
implemented within the same program in which it works, that is, it does not need libraries
externals like in other languages(C++for example), even so, there is also the possibility of
to be able to use external libraries to enhance certain fields of the system. These libraries
They should be in one format or another depending on which platform we are working with.
howDLLfor Windows and .java for Android
Variables[edit]
GML does not require the compulsory declaration of variables to work with them, that is, it is sufficient
by assigning it a fixed value once anywhere. For example:

variable=<value>;

In this case, the variable is already declared and can be used generally, however, GML
it also includes a "var" block mimicking the variable declarations of other languages,
being able to declare a number of variables in the program without the need to assign them a
value (if not, it is automatically0 ). For example:

var xx,yy,ss;

Game Maker also works with constants, which can be assigned from a function.
of the program (plus those that already exist therefore).

Within the GML code, there are two types of working variables, the variables
local variables global. Local variables only work within a
"object", that is, it does not exist outside the "object" or code block(en caso de haber sido
declaradas con "var") que la trabaje (lo cual permite usar el mismo nombre de la variable en
another object). On the other hand, there are global variables, which use the
prefixglobalbefore the variable name, for example:

global.variable=0;

Global variables are used throughout the program, so there can only be one.
global variable with the same name, and its value can be affected from anywhere
program/code parameter.
GML can also handlearraysin a very simple way and very similar to C++.
They must be declared in the following way:

array[index1,index2];

Arrays in Game Maker can be 1 or 2 dimensions and can contain a mix.


of strings and real values, but not other arrays. There is also a limit on sizes:
The indices must be between 0 and 32,000, and there cannot be more than 1,000,000 values in one.
same array.
GML also has functions used to create and edit six data structures.
simple. These functions are only available to users who have the Pro version of
Game Maker. The available data structures are Stacks, Queues, Lists, Maps,
Priority queues and Grids.
Types[edit]
Due to the simplicity of the GML, it only has two types of variables. Any variable can
carry any type of data without any type of declaration.
Strings are ASCII character strings (or Unicode and ANSI in the case of GM 8.1) that
They can be of any length. As GM prefixes the size of strings as values.
4-byte integers, a string can actually have no more than 4,294,967,296
characters, if this number is exceeded, the characters are cut off from the beginning
until the total number of these is less than the limit. However, generally the
strings are much shorter.

ty_string

Boolean are used to distinguish a character of type true or type false, it does not store any value.

Real Values are signed floating point numbers. That means they can
be positive or negative numbers and may have a decimal part. Since version 6.1,
GM allows the representation of hexadecimal values as reals in the code, if
preceded by the character $. In version 6, the handling of real values had abugwhat
it caused precision errors when working with high real values. The bug also exists.
in GM 7 and 8, but it was mitigated with more precision.

ty_real

Since GML does not have boolean values, statements that require boolean values (such as if)
they will evaluate any real value greater than 0.5 as true and any real value less than or
equal to 0.5 as false. In GML there are also constants for
defecttrueyfalsewhich correspond to 1 and 0 respectively, and can be used to
make the code more readable.
Scope[edit]
In GML, there are two types of local variables: instance-local and script-local.
any other piece of code that has its own container). Be local to an instance
it means that this variable is tied to that particular instance and that to be called from
another instance must use as a prefix the name of the instance that contains the variable. Be
Local to a script means that the variable can only be used in that script and that upon finishing
once this is processed, the variable expires. The term 'local' without further specifications, usually
it refers to a local instance.
By default, a variable is local to an instance but not local to the script in which it is used.
To make a variable accessible to all instances (and scripts), it can be defined
using the global prefixglobal.foo=bar; or declared explicitlyglobalvar
foo,bar;Using the first form, the variable must always be called using the
prefixglobal.the statement withglobalvardoes not require any prefix. To make a
a local variable in a script uses the keywordvar: var foo, bar;.
One can access a variable that is local to one instance from another instance using
how to prefix an instance identifierinstance.variableThere is no way to access
a local variable of a script from another, unless the variable is passed from script to script
as an argument.
An instance can execute code in another instance using the "with" statement. For example,
the following piece of code, placed in a collision event, can be used to destroy
to the instance that collides with the current one. When a collision event is triggered, Game
Maker automáticamente crea la variable "other", la cual se refiere a la instancia envuelta en la
collision.

with (other) {instance_destroy();}

Note that when a variable is local to a script, it is independent of any instance.


For example, the following code would work even though the variablefoois not defined
inAnotherInstance.

var foo;
foo="bar";
with (AnotherInstance) {show_message(foo);}

Learn GMLstep by step


FORDAVID· JUNIO 9, 2015
So far we have talked about the graphical interface of Game Maker Studio and
all the resources that the program offers us. We have detailed what they are
sprites, how to add and modify backgrounds, add sounds, create paths, lines of
time... and the most important thing: to create objects with their events and actions so that
our game should be as interactive as possible.

But if we really want to enhance our games, create more projects


complex or expand the features and options, it is clear that programming is needed
code. And Game Maker gives us that possibility.

Learning to program a language shouldn't be difficult, it's a matter of practicing.


practicar y practicar. Aunque veas cientos de ejemplos y te leas cómo funcionan
Algorithms, if you don't write lines and lines of code, you will not learn to create.
new games or improve what you already know. I don't want to be a bother on the subject and
Insisting too much, the theory is very good, but the key is to put it into practice.

.1 How I will focus the posts


. What language does Game Maker use?
. Where can we use it?
. 4 How we refer to resources
.5 ¿Qué es un programa? ¿Cómo funciona el código?
. 6 Conclusion

How I will focus the posts


If you have already programmed in other languages, you will adapt very easily to the language.
of Game Maker Studio, since it is less restrictive than other languages of
programming.

My intention is to teach the language from scratch, so it is possible that much of


the posts I make are not of much interest. But I hope to contribute to everyone who
they want to start from the beginning.

I will teach the programming language with small practical examples that
you can take advantage in any game you make, and this way we see that the code is
usable in many cases.

So far, detailed explanations of how they work have been necessary.


sprites, sounds, objects, events, etc... but in the GML section I will do
much shorter posts, I hope that this way I can write more
frequently.

At the same time, I will also start adding the tutorials. I will begin with the first one.
Tappy Plane game, this way we see in a very simple way how to create a mini
game, which can be perfectly valid for a website or a game of
mobile.

What language does Game Maker use?


If you are wondering what programming language Game Maker uses, we will say that it uses
GML. What does GML mean? GML stands for Game Maker Language. It is
a programming language unique and exclusive to Game Maker, although it
it looks a lot like Java or C. The advantage is that it is much more flexible. I will make a post
specific to the different ways that can be written, but it is important
use an appropriate style and always do it the same way.
It goes without saying that the Drag & Drop actions we have seen so far
it has its equivalent in GML.
Where can we use it?
You can write code in various places in Game Maker, just like we have
Got it. Let's refresh it:

. Scripts.Scripts are pieces of code that we can take advantage of in


any object. It is designed to write your own functions.
. Events. Within an object, we can write code with the Execute action.

Code Remember that you can also combine your written code with
other actions that we have dragged.
. Code to create the room. We already saw that from therooms editorwe can
put specific code in the room. We can say that it has its own

eventCreate . Podemos añadir código cada vez que se entra en la room.


. Code to create in the instance. We know that the actions of the

eventCreate it will be executed in all the instances we have in the


room. But it is possible to add code to one or more instances from the room.
Let's remember to take into account the order of execution of game events for
to have no surprises.
How do we refer to resources?
Ya hemos ido comentando como solemos llamar a los recursos. Para poder
using them while coding, it is important to know that they can be used
letras, el guiónbajo “_” y números que no estén al principio. Por ejemplo
"spr_wall", "SprWall", "sprwall6" are valid. But if we use names like
"spr wall" or "6 wall", we will not be able to use it in GML.
Another important topic, Game Maker distinguishes between uppercase and lowercase letters. That is to say,

for Game Maker it is different "sprwall", "SprWall" or "SPRWALL". But it is


Of course, we also should not try to confuse ourselves.
I will use the same format that is seen in system constants and variables.
game maker. i will write everything in lowercase, i will use the '_' a lot and i will use prefixes
to identify the different resources spr_, obj_, snd_, etc. It's curious because I have
programmed in other languages and I have never seen this nomenclature.
When we see code examples, we will see how important it is to know if
When we write "wall", we are referring to a sprite, an object, or a variable.
What is a program? How does it work?
code?
When we add a new event, we can drag actions that will be executed.
in that event. How would it be done in GML? Exactly the same.
A code block is a set of instructions that are executed line by line.
a line. That is why it is said to be sequential. It can be a simple instruction,
like a sum or it can be a complex instruction, like calculating the distance
between two objects.
Writing the instructions is as simple as this:
instruction1
instruction2;

We see that each instruction ends with a semicolon ';', it is a way of
tell the program that it has completed that instruction. Because Game Maker
it's quite flexible, as we have discussed, it's not mandatory to put ';', but I
I recommend it for keeping the code as organized as possible. Another example:
Ejemplo de código GML en el evento Create. Vemos que se declaran algunas variables para usarlas en otros
events.

Conclusion
We have made a small explanation of the importance of programming with code.
With a brief introduction, we have discussed the programming language.
what we can use with Game Maker Studio. In the next post, I will talk about the
variables and how we can use them in our code.
Program.
A program is a set of instructions called statements, which are
interpreted by GameMaker: Studio with the purpose of making something happen inside
from a game. That 'something' can be as simple as adding 2 plus 2 to
to obtain 4, or as complex as making an enemy flee when their health drops from
certain level. The structure of a program varies enormously depending on the
functions it uses, but reducing it to its most basic structure, the representation of
any program would be:

{
<statement>;
<statement>;
...
}

A program must begin with the symbol '{' and end with the symbol '}', and between
these two symbols locate the sentences, each separated by a symbol of
punto y coma ';'. Ahora veamos un típico programa de GML , más precísamente un
program created in theScript EditorGameMaker:Studio
There are various types of sentences, which will be discussed in the following
sections of the manual.

Variables and their scope.


The different types of available variables are discussed.
in GameMaker:Studio.

Like any other programming language, GML uses variables as the unit
basic for most programming operations. Variables are used
to store information in memory for later (or immediate) use. They are
assign a name to be able to call them in functions and programs. A variable in
GML can store a real number, (like 100, 2.456575, -56, etc.) or a string.
Hello, world.

Colloquially, a variable is a container for holding a value that will be used.


in one or more operations or functions. Imagine the value "pi", a real type number
It holds the value 3.14159265 (etc...). Why? It is easier to say 'pi' than 'three.
point fourteen fifteen ninety-two sixty-five. In this way, to give a name to the
valores facilita su uso, y también nos asegura que aun cuando el valor de la variable
change, its name will always be the same. The name of a variable in GML always
it must start with a letter and can only contain letters, numbers, and the underscore '_'
(no accented or special characters are allowed). Its length must not exceed
64 characters. Examples of valid variables arespeed, lower_limit, number1;
invalid names could be5 speed, upper limit, onumberIn others
programming languages require you to 'declare' a variable before using it. This
it means that the computer is instructed with the name that is desired
identify that variable, in such a way that memory space is reserved for it
store any data that you want to "put" in the variable. This is not always
necessary in GML, since it depends on the range of the variable. There are four categories.
of variables in GameMaker: Studio and each one has its own scope (the area of
operation or its domain). The four categories are:

instance:The most common category.Variables are defined within the


instance. They are unique and specific to their instance and can be used in any
event and any function within that instance.

localThese variablesthey are declared using the function 'var'. A local variable
it is only valid within the event or script in which it is created. In this
case GameMaker: Studio will create the variable, it will be used for the duration of the
event and then it will "forget" about her, which will cause the error to occur
unknown variable if you try to use it later.

global:A global variablepbelongs to the entire game environment, and not to one
specific instance (even though it is declared within an instance). In a
Initially, it has to be declared as global, but after this, any
instance can read or change its value. The value of the variable will always reflect
the last operation in which he was involved, regardless of what instance it developed
operation.

Internal variables: They are special variables inherent to the objects and
rooms in the environment. They have been there since a room or object is
created. They can have instance or global scope, but not local scope. There is a
a large number of these variables, each with very specific uses, are
describe con detalle a lo largo del manual en las secciones correspondientes.

Instance Variables
The scope of an instance variable is limited to the instance where it is defined.
create.
An instance variable is created within the instance of an object and is considered
unique for that instance: many instances of the same object can have the same
variable, but each one can store a different value, since those variables are
unique to each instance. How do you create an instance variable? You only need to
assign it a value, as shown below:

pociones = 12;
vida = 100;
nombre = "Juan Pérez";
fuerza = 5.5;
armadura = -2;

It is only necessary to provide a name and a value (numerical or alphabetical) for


initialize a variable and make it ready to be used in the instance of the object that is being
coding. Of course, these variables can be used and modified within the
instance in different ways, for example, subtracting an amount from the variable "life"
in a collision event:

life -= 5 + armor;

If life 'life' is at 100, its value will change to 97 (100 - (5 + -2) = 97). This is a
simple example, you could replace 'armor' with the value -2, but what happens if
Do you use that value in different places and decide to change it? It would have to go everywhere.
code and change each -2 to the new value, which takes time and can lead
To errors! But when using a variable, all that needs to be done is to reassign it a new
value, which will be used automatically in the code, increasing flexibility and
facilitating error correction. Even if the value were not to change, it is easier
remember what use a variable called 'life' has that only shows a number.

GameMaker:Studio also has a set of internal variables with which it is


important to familiarize, as a variable could accidentally be created with a
same name, which would likely cause errors. The internal variables are
they are shown in a different color in the code editor and are also suggested in
the auto-complete bar at the bottom.

Local variables
A local variable is declared, used, and then discarded.
Local variables are only created for specific events, when that event
I finished, the variable is discarded (The only exception to this is scripts, where a
a variable declared as local remains local to the script, and then it is discarded). Why
What would we need it for? Variables take up space in memory, and it can be
that we will only use them for an operation or function, in that case it is only
necessary to keep them in memory only for the time they are used. This keeps the
clean and orderly base code, while optimizing memory space for
the things that are truly necessary. To declare a local variable we use the
functionvarin this way:

var i, number, text;


i = 0;
numero = 24.5;
Hi there!

All the variables from the previous example will be 'forgotten' (will disappear from memory)
at the end of the event (or the script) in which they were created. You must be careful and not give
a local variable the name of an instance variable already created within the object
executing the code, and also, not intending to use the value of the variable
local outside the event where it has been declared. These variables are used in a way
frequent, especially in cycles, to count iterations, or when a value is used
recurrently in an operation that will not repeat itself. Here a couple of
examples:
var i = 0;
repeat (10)
{
inventory[i] = 0;
i+=1;
}

The previous code creates a local variable named 'i' and initializes it to zero, and sets it
to 0, everything in the same line. In previous versions of GameMaker it was necessary to declare
first the local variable first and then assign it a value, but in this version
you can declare and assign a value at the same time. In the example, the value of the
variable is used to initialize an array. Since the variable "i" will not be used elsewhere
subsequent operations may have a local scope. Here is another example:

var xx,yy;
xx = x - 32 + irandom(64);
yy = y - 32 + irandom(64);
instance_create(xx, yy, obj_blood);

Here the local variable has been used to store random coordinates used for
create an instance. It can be seen that it is not strictly necessary to use these
variables, but for the sake of clarity and ease of use we do it this way. It is much
more clear and obvious what is being done, than using code like this:

instance_create(x - 32 + irandom(64), y - 32 + irandom(64), obj_guts);

A detail about local variables: Being unique to the event that executes them,
It is also possible to use them in other instances through code! That is, we can
use local variables to adjust and change things in other instances through the
statement "with()" (there is a section about this in section Generalities of
language in the manual). The code would look like this:

var num = instance_number(obj_Enemy);


with (obj_Enemy)
{
if num>10 instance_destroy();
}

This code works because the variable "num" is local to the event (or script) in which
It is contained, NOT IN THE INSTANCE NOR THE GAME ENVIRONMENT, which allows it to be used.
in any function in any object as long as it is in the same block of
code.

Global variables
In simple terms, a global variable is a type of variable that, once declared,
does not belong to any instance, but can be read by all of them. The variables
globals must be declared, just as happens with local variables, but at
the difference between these, a global variable remains in memory until the end of
game. For example, a global variable can be created to keep track of
player's bullet count and simply update this variable in different
game points. A global variable does not belong to a particular instance and
it can be read, changed, and used by all instances at any time,
but any change made to the variable is also 'global', that is, the change
It affects all instances that use this variable. Let's see an example of this:

globalvar food;
food = 5;

we have created a new variable called "food" which has been declared as
"food" is available for any instance, for example, there could be a
object "food" that the player collides with, and in that collision event
we would have

food +=1;

We could have another object that draws the value of "food", this way:

draw_text(32, 32, "food = " + string(food));

Through global variables we can change values and see those changes reflected in
all instances that reference those variables. In the same way that
with local variables, care must be taken not to name them the same way as
any instance variable, as this would cause problems and it would facilitate the
appearance of errors in the game. As a resource to avoid these inconveniences,
we can call global variables using the reserved word "global" followed by
from a point '.' before the variable. This is illustrated below:

global.food = 5;

Con este método, debemos usar la palabra "global" cada vez que deseemos usar la
variable, for example:

global.food += 1;
draw_text(32, 32, "food = " + string(global.food));

GameMaker:Studio also has a collection of 'predefined' global variables,


so they should be taken into account in order not to name them the same way as
instance variables or to their own global variables. However, these variables are
easy to detect as they are displayed in a different color in the code editor and
appear in the auto-complete bar at the bottom. Most of the
predefined global variables are very specific and rarely used, but there are
three variables in particular that are very useful and common, which are described as
continuation listed below:

oscore
ohealth
olives

score
Global variable to store the game score.
Syntax:
score;

Return: Real

Description
This variable has a global scope and is used to store a numeric value that
it generally refers to the score of the game, however, it does not necessarily have to
Just because the name is 'score' does not mean it has to be used.
for the marker... it can store the value you want.

Example:
if place_meeting(x, y, obj_Bullet)
{
score += 10;
instance_destroy();
}
This code checks the current instance to determine if there is a collision with any
instance of the object "obj_Bullet", and if there is one, add 10 to the global score and to
continuation is destroyed.

health
Global variable to store health points.
Syntax:
health

Returns: Real.

Descripción
This variable has a global scope and is used to store a numerical value that
it generally represents the player's health, but it should be taken into account
that this does not necessarily have to be this way. Although the name is
health can be used to store any useful numerical value for the game.

Example:
if place_meeting(x, y, obj_Enemy)
{
health -= 10;
if health <= 0 instance_destroy();
}
The previous code checks if there is a collision with the object indexed in the variable.
obj_Enemy, and if there is one, subtracts 10 points from the global health variable and then
determine if the value of that variable is less than or equal to zero. If this is met
condition, the instance that executes the code is destroyed.
Accessing variables from others
instances
Several methods are described to call variables in others.
instances.

Previouslyit was described how to create and use variables within an instance, or of
globally, but what happens when you want to access from an instance a
variable in another different instance? There are many cases where this occurs.
situation, for example, if in a collision event with a bullet one wanted to know
how much damage does the bullet cause, reading one of its variables, or if one wants to stop it
movement of all the bullets in the room; or move the protagonist to a position
determined, to mention a few. Let's see how to achieve it through GML.

Using a point.
This method consists of using the object's name as an identifier, followed by a
dot '.', followed by the name of the variable to be changed or assigned. It is
to say

obj_ball.speed = 0;

What the previous code does is adjust the speed of ALL the instances of
object 'obj_ball', so this method allows changing a variable in all the
instances of some object. And what if you want to change the speed only?
a particular instance, instead of all? In that case, the principle is the same,
except that instead of using the object's name as the identifier for all its
instances, we use the instance identifier to tell it
GameMaker: Studio which we only want to handle a single instance.

Well, but what is the instance identifier? It is an identification number.


unique assigned to each instance created in the game. When an instance is placed in
a room from the room editor, this identifier appears at the part
it drops down from the screen when the mouse pointer hovers over the instance, but equally
In this way, if an instance is created through code, it also has its identifier.
unique. The instance ID is always greater than or equal to 10,000 (ten thousand), and this number
can also be used as an identifier to the left of the point. Note: The
punto es interpretado como un punto decimal en un número real, así que para evitar
This, the id must be enclosed in parentheses!

The following example shows how this should be written:

(100012).speed = 0;

Additionally, certain special objects or even variables can also be used.


to identify instances in games. A special object a special type of
variable that GameMaker: Studio recognizes and interprets in a particular way. When dealing with
With instances, we have the following special objects:
Keyword Description

It refers to the instance that is executing the block of


self
código actual.

It refers to the other party involved in an event of

other collision

or the other instance of a sentencewith.

all All active instances at the moment in the room.

No instance (It may seem strange, but it is


no one
very useful at times, as will be seen below).

In the case of using variables, it is simply about storing the identifier of


instantiate a variable, which is then used before the dot. In the next
example illustrates this...

Using a keyword to adjust all instances:

if instance_position(mouse_x, mouse_y, all) = noone


{
all.speed = 0;
}

Using a variable to adjust a single instance:

var nnn;
nnn = instance_create(100, 100, obj_ball);
nnn.speed = 8;
nnn.direction = random(360);

All of these are valid ways to read and adjust variables in other instances, and
It works because the dot is actually an operator. It takes a value as an operand.
left and a variable (direction) as the right operator, and returns the direction of
that particular variable in the indicated object or instance. All names of
objects and special objects from the previous paragraphs actually represent values,
These values can be treated like any other value. The Names of objects,
special objects and instance identifiers can be used in many
other functions, since GMS treats them as constants. write.

The use of 'other'


There are two situations in which the reserved word 'other' can be used to make
reference to a specific instance: When used in a
functionwith(explainedhere) or when it is used in acollision event, What is the case
what we will see next.

A collision event occurs only between a pair of instances. Of course, it


they can present multiple collisions between multiple instances, but each collision is
treated by GameMaker: Studio one by one, between the instance in which it was defined
collision event and the "other" instance involved. Let's imagine we have a
player object, enemy objects, and bullet objects shot by enemies. It
you can assign each enemy a bullet instance, but with different capacity of
damage calculated randomly when that instance is created, for example:

var nnn;
nnn = instance_create(x, y, obj_Bullet);
nnn.damage = 5 + irandom(5);
nnn.speed = 8;
nnn.direction = point_direction(x, y, obj_Player.x, obj_Player.y);

Note that we are adjusting variables using the point method before
explained. Now, what happens with the player object? How to make it know how much
What damage will be received? Using the event of collision (from the player object).

hp -= other.damage;
if hp <= 0 instance_destroy();

the above code will read the value stored in the variable "damage" from
the distance and will subtract it from the player's "hp" variable, then it will check if "hp" is
less than or equal to 0. If it is, it will destroy the instance of the player object. It is important
highlight that this use of others only works in the event of a collision and that it is necessary to
make sure that the variables of the other instance exist, or it will cause
error. However, through other means, values can be assigned to variables and even
crear nuevas , usándola en el evento de colisión así:

other.mana += 10; //adds ten to the variable 'mana' of the other instance
other.hit = true; //set the 'hit' variable of the other instance to true,
creating it if it does not exist

Assignments
An assignment is the method used to store a value in a variable. All
the assignment has the following structure:

<variable> = <expression>;

The simplest expression can be a simple value, but it can also be more.
complex (one or several operations). In addition to assigning values, we can also
add a value to the current value of the variable, using +=, for example:

a += b;

Similarly, you can subtract using -=, multiply using *=, divide
using /=, or using bitwise operators |=, &=, ^=. You can also add or
subtracting from a variable, using ++, --.

a++; //Add 1 to the value stored in a

You might also like