I don't like using "other" keyword

L

LawH

Guest
I feel like using it is too easy and will make me a bad programmer in the end.

Is there a way to avoid using "other" all together? As an example of what I might be trying to do is, that if a characters variable == something, then do this. However, one might run into problems if there are multiple instances of that same object.
 
L

LawH

Guest
How do I get the instance id from an object without using the other?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Use a Step event and instance_place to get the instance's ID. This mimics the behavior used by the Collision events. If you want to be able to collide with multiple instances in the same step, use instance_place_list.
 
I feel like using it is too easy and will make me a bad programmer in the end.
Really man? This makes totally no sense. You think being a good programmer is being like the dude in Die Hard 4?
A good programmer makes his/her code efficient, easy, reusable, readable, looks at problems at different angles, finds the best solution to solve them... If your solution fits in one line, that's just better.
Even the best guitar players in the world play open G chords, and there's no shame in it, even if it's the first chord beginners learn.
 
L

LawH

Guest
Really man? This makes totally no sense. You think being a good programmer is being like the dude in Die Hard 4?
A good programmer makes his/her code efficient, easy, reusable, readable, looks at problems at different angles, finds the best solution to solve them... If your solution fits in one line, that's just better.
Even the best guitar players in the world play open G chords, and there's no shame in it, even if it's the first chord beginners learn.
I was expecting a comment like this, but I'm glad it was only the one, so thanks to the others for staying on topic. Imagine if you'd have to transpose the G chord without understanding what a major or a minor chord actually is, let alone not understanding what a chord even is.

I could just copy/paste code from other people and create what I need, but that does nothing to help me understand what I am actually doing. I will use "other", once I understand what is actually happening. This is why I asked the question. Once I know what a g minor chord is, I can play it with a better conscience.

Understanding is so much better than just droning away with no knowledge of what it is you are actually doing. If I were to change programming languages, I would have little to no idea how to create this same effect. For example, I started with python. To my knowledge it has no "other" keyword.
 
L

LawH

Guest
Use a Step event and instance_place to get the instance's ID. This mimics the behavior used by the Collision events. If you want to be able to collide with multiple instances in the same step, use instance_place_list.
I'll have a look at this. I assume it checks a set area and sees which instances share their coordinates with that area?
 
I was expecting a comment like this, but I'm glad it was only the one, so thanks to the others for staying on topic. Imagine if you'd have to transpose the G chord without understanding what a major or a minor chord actually is, let alone not understanding what a chord even is.

I could just copy/paste code from other people and create what I need, but that does nothing to help me understand what I am actually doing. I will use "other", once I understand what is actually happening. This is why I asked the question. Once I know what a g minor chord is, I can play it with a better conscience.

Understanding is so much better than just droning away with no knowledge of what it is you are actually doing. If I were to change programming languages, I would have little to no idea how to create this same effect. For example, I started with python. To my knowledge it has no "other" keyword.
You're putting words in my mouths I never said. You said using "other" will make you a bad programmer. I called the BS in that, that's all.
Yes, you can never ever use "other" and have a perfectly fine working game. It's just that a look at the debugger will show you it's ALWAYS there, whether or not you want it to. Use it, or don't, but it WILL be computed, so you have no real gains using other ways to access it.
 
L

LawH

Guest
You're putting words in my mouths I never said. You said using "other" will make you a bad programmer. I called the BS in that, that's all.
Yes, you can never ever use "other" and have a perfectly fine working game. It's just that a look at the debugger will show you it's ALWAYS there, whether or not you want it to. Use it, or don't, but it WILL be computed, so you have no real gains using other ways to access it.
You're missing the point entirely, so I won't feed the troll any more than necessary. Read it again, and chill out, maybe you could learn something.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Gains or not, who are we to dissuade people from wanting to know alternative ways of doing things, whether it's for learning purposes or just for the heck of it? :)

I'll have a look at this. I assume it checks a set area and sees which instances share their coordinates with that area?
It checks for collisions by using the collision masks of the calling instance and either a specific instance or all instances of an object (depending on whether you pass an instance ID or an object ID to it). Normally, the collision mask is the same as the bounding box of the sprite that is assigned to an instance. You can also assign a separate mask, in which case that mask's bounding box will be used. It's important to note here that if an instance has no collision mask - either because it doesn't have a sprite or mask assigned or because the collision mask is 0x0px - no collisions can be registered.

I could just copy/paste code from other people and create what I need, but that does nothing to help me understand what I am actually doing. I will use "other", once I understand what is actually happening. This is why I asked the question. Once I know what a g minor chord is, I can play it with a better conscience.

Understanding is so much better than just droning away with no knowledge of what it is you are actually doing. If I were to change programming languages, I would have little to no idea how to create this same effect. For example, I started with python. To my knowledge it has no "other" keyword.
Then let's cover this aspect too! ;)

Your code always runs under a specific scope. You can think of this as the "viewpoint" of the code. Usually, this is the scope of the instance of the object the code is in. Performing certain things like setting or reading variables, or calling functions or methods, will always be done under the currently active scope, so that one instance setting a variable will set its own variable rather than that of another instance.

It is possible to change this scope in various ways. What this means is that one instance can essentially run code from the viewpoint of another instance, or access the variables of another instance. One such way is by using other. There are two ways to use it, and the one being discussed here is inside a Collision event. To understand how or why other works here, we first need to understand how Collision events work.

This can be summarized as such:
GML:
var _inst = instance_place(x, y, object_to_collide_with)
{
    // Collision event code is fired here!
}
This means that a Collision event can register collisions against one instance of a particular object per step, and the event is fired if (and only if) a collision is detected. In this case, you can change the scope to that instance's viewpoint via other. In fact, if you used the code snippet above in a Step event, _inst works exactly the same as other works in a Collision event. This means that you can prefix a variable with other.variable and access the variable of the instance you're colliding with. You can also fully switch the scope to the instance you're colliding with via with (other).

For the sake of completeness: The other case (no pun intended) where you can use other is inside of a with statement. Here, it refers to the instance that originally executed the with statement, so it can be used to change the scope back to the default after having changed it with a with statement.
 
L

LawH

Guest
Gains or not, who are we to dissuade people from wanting to know alternative ways of doing things, whether it's for learning purposes or just for the heck of it? :)


It checks for collisions by using the collision masks of the calling instance and either a specific instance or all instances of an object (depending on whether you pass an instance ID or an object ID to it). Normally, the collision mask is the same as the bounding box of the sprite that is assigned to an instance. You can also assign a separate mask, in which case that mask's bounding box will be used. It's important to note here that if an instance has no collision mask - either because it doesn't have a sprite or mask assigned or because the collision mask is 0x0px - no collisions can be registered.


Then let's cover this aspect too! ;)

Your code always runs under a specific scope. You can think of this as the "viewpoint" of the code. Usually, this is the scope of the instance of the object the code is in. Performing certain things like setting or reading variables, or calling functions or methods, will always be done under the currently active scope, so that one instance setting a variable will set its own variable rather than that of another instance.

It is possible to change this scope in various ways. What this means is that one instance can essentially run code from the viewpoint of another instance, or access the variables of another instance. One such way is by using other. There are two ways to use it, and the one being discussed here is inside a Collision event. To understand how or why other works here, we first need to understand how Collision events work.

This can be summarized as such:
GML:
var _inst = instance_place(x, y, object_to_collide_with)
{
    // Collision event code is fired here!
}
This means that a Collision event can register collisions against one instance of a particular object per step, and the event is fired if (and only if) a collision is detected. In this case, you can change the scope to that instance's viewpoint via other. In fact, if you used the code snippet above in a Step event, _inst works exactly the same as other works in a Collision event. This means that you can prefix a variable with other.variable and access the variable of the instance you're colliding with. You can also fully switch the scope to the instance you're colliding with via with (other).

For the sake of completeness: The other case (no pun intended) where you can use other is inside of a with statement. Here, it refers to the instance that originally executed the with statement, so it can be used to change the scope back to the default after having changed it with a with statement.
How would I be able to check collisions and exchange variables in a very stripped manner, in let's Python, or any other language?

Right now I use other in a couple of collisions events, and one with event. It's very powerful, but since I never got far enough if python or c#, I'm not sure what the engine is actually checking. For example, it took me a while to understand trigonometry when I was trying to get a line to move away from a point from an angle. I knew I could copy/paste a line and it would work, but in the line used in a tutorial, the "direction" keyword was still used, and I felt I needed to understand that as well. I feel that same way about this exchange of variables. I feel that if given another programming language, I would not know where to begin to achieve this same result without the "other" keyword, which in turn feels like it is making me a less proficient programmer overall.

I can use shortcuts once I understand what is behind them, and since I don't fully understand "other", in a sense that I don't know another way of doing it, I don't feel that I should blindly use it without understanding it.

In a way where if I would ride a bike and not know how it would work. Riding it would be fine, but it would be nice to know at last that it's the peddling that turns the wheels, which makes the bike go wroom.
 

chamaeleon

Member
Quote based on a fear of not learning enough by overusing engine specific premade functions that will hamper me from understanding what is actually happening in a program - Me, 22.2.2021.
This fear, with respect to the use of the keyword other, is unfounded. -My unsolicited opinion, 2/21/21.
My other opinion, other is an integral part of using with() and collision events. If you wish to avoid using these feel free. No one is forcing you. But again, my opinion is that it does not make life easier, nor do I feel using other and these other constructs makes it difficult to understand how GMS works.
There's nothing at all stopping you from creating any game you want, using a single object of which you have a single instance by having it draw all sprites and text in the game. Complete control. Knock yourself out.
 

chamaeleon

Member
I don't fully understand "other", in a sense that I don't know another way of doing it
The with() code block changes what instance is currently executing code. other refers to the original instance for convenience. Nothing more to it. Use other if you need to refer to the original instance, don't if you don't.
Collision events by definition will involve two instances. other refers to the other instance that is not currently executing the collision event code. Nothing more to it. Use other if you need to refer to the other instance, don't if you don't.

In the case of with() you could declare a local variable containing the id of the current instance before the with() statement, and use that variable instead of other. But since there's no difference in usage this way, what have you gained in understanding?
GML:
var my_other = id;
with (some_instance) {
    x = my_other.x; // can't use id here because it would refer to some_instance.id instead of the original id
    y = my_other.y; // can't use id here because ...
}
 

saffeine

Member
i totally get where you're coming from with the wanting to know what's under the hood, i'm exactly the same for better or worse.

that out of the way, whether this is how any competent game engine does its checks is out of my level of expertise, but here's what i'd do, and what i've done a few times for smaller prototypes in different languages:

1. create an object / struct / array to represent what we call objects in gamemaker.
- the objects will hold variables such as x, y, width, height. the bounding box may or may not have its own variables too.
- each time one of these objects is created, it's added to a globally scoped array of nothing but these objects, separated by type ( one array for enemies, another for projectiles, you get the idea ).

2. create a function that would effectively be instance_position.
- this function takes the position + bounding box of the object calling it, and compares it to the position + bounding box of each item in the aforementioned array. if the objects are tile-based, this can be a hell of a lot faster.
- if the bounding boxes overlap, you could return a list of all boxes that overlapped, or return a specific one ( such as the first ).

GML:
/*
    pseudo-code example.
*/

function inst_place( _sourceobj, _desttype ){
    var _bbox1    = _sourceobj.bbox;
    
    for( var i=0; i<_desttype.length; i++ ){
        var _bbox2    = _desttype[i].bbox;
        
        if( boxes overlap ){
            return _desttype[i];
        }
    }
}

collision = inst_place( this, global.__enemylist ); // this would return the specific object, or 'other'.
PLEASE take this with a pinch of salt, i'm just a goof with a keyboard, and i'm sure game engines are built differently for efficiency, but it's a starting point perhaps.
each engine has its own way of doing things, but i do understand the interest in trying to build a system from scratch. i love to do the same, even if it does come out choppy.
hope that this is maybe what you were looking for, and that the ball is close enough to the court. i'm sure someone will tear it apart in due time.
 
L

LawH

Guest
This fear, with respect to the use of the keyword other, is unfounded. -My unsolicited opinion, 2/21/21.
My other opinion, other is an integral part of using with() and collision events. If you wish to avoid using these feel free. No one is forcing you. But again, my opinion is that it does not make life easier, nor do I feel using other and these other constructs makes it difficult to understand how GMS works.
There's nothing at all stopping you from creating any game you want, using a single object of which you have a single instance by having it draw all sprites and text in the game. Complete control. Knock yourself out.
This is missing the point a little. I am using the other keyword, but I would like to know how the function works. Having other references to how it functions without the built in function will make me a better programmer, and I don't think that's a matter of an opinion. Like said before, I am a better programmer now that I understand at least the basics of trigonometry, without just copy/pasting a line of code into my program and celebrating that it works. It doesn't feel right, even though it does work. Having full understanding of what you're doing will expand your knowledge, and that I think is the definition of being better at something. I'm not looking for an alternative to other, I am looking for what this function inteils. Once I can create the "other" function using as simple code as possible, I know I can do it if needed, but since then I would know how it works, I can make a decision whether to use "other", or to use my code, if some particular situation arises.

Other examples to make my point, is using a function like place_meeting. The program checks whether a coordinate of an object is within the designated area of the coordinates set in another instance. It's pretty self explanatory to me, but perhaps not to someone completely new to programming. Since I understand that, I don't feel the need to expand on using this shortcut any further. The same goes with alarms. I don't use them, since I know there is a limited number of them. I make alarms myself. Since I know how that works, I could use the engine alarms, but creating my own alarms seems a lot better for me. It's not about not using something, it's about not even pretending to understand how something works, but by actually understanding it.
 
L

LawH

Guest
i totally get where you're coming from with the wanting to know what's under the hood, i'm exactly the same for better or worse.

that out of the way, whether this is how any competent game engine does its checks is out of my level of expertise, but here's what i'd do, and what i've done a few times for smaller prototypes in different languages:

1. create an object / struct / array to represent what we call objects in gamemaker.
- the objects will hold variables such as x, y, width, height. the bounding box may or may not have its own variables too.
- each time one of these objects is created, it's added to a globally scoped array of nothing but these objects, separated by type ( one array for enemies, another for projectiles, you get the idea ).

2. create a function that would effectively be instance_position.
- this function takes the position + bounding box of the object calling it, and compares it to the position + bounding box of each item in the aforementioned array. if the objects are tile-based, this can be a hell of a lot faster.
- if the bounding boxes overlap, you could return a list of all boxes that overlapped, or return a specific one ( such as the first ).

GML:
/*
    pseudo-code example.
*/

function inst_place( _sourceobj, _desttype ){
    var _bbox1    = _sourceobj.bbox;
   
    for( var i=0; i<_desttype.length; i++ ){
        var _bbox2    = _desttype[i].bbox;
       
        if( boxes overlap ){
            return _desttype[i];
        }
    }
}

collision = inst_place( this, global.__enemylist ); // this would return the specific object, or 'other'.
PLEASE take this with a pinch of salt, i'm just a goof with a keyboard, and i'm sure game engines are built differently for efficiency, but it's a starting point perhaps.
each engine has its own way of doing things, but i do understand the interest in trying to build a system from scratch. i love to do the same, even if it does come out choppy.
hope that this is maybe what you were looking for, and that the ball is close enough to the court. i'm sure someone will tear it apart in due time.
This is exactly what I mean. Having something to get started with is exactly what I wanted. I will have a close look at this and see if it opens up some of those unknown territories for me to better help me understand what is actually happening. The keyword "other" entails so much, that simply using it feels like I am just droning away without respecting what that single work summarizes.

Thanks for this my friend!
 

saffeine

Member
This is exactly what I mean. Having something to get started with is exactly what I wanted. I will have a close look at this and see if it opens up some of those unknown territories for me to better help me understand what is actually happening. The keyword "other" entails so much, that simply using it feels like I am just droning away without respecting what that single work summarizes.

Thanks for this my friend!
the main thing to take away is that 'other' is just one of many variables that represent a returned value. it's up to you what value it is that you return.
self returns the id of the object calling it ( or is just the object itself, like this in java-adjacent programming ), other returns the id of the object involved in a function that isn't the one calling it. how you get those values is your choice.
 

Roldy

Member
How would I be able to check collisions and exchange variables in a very stripped manner, in let's Python, or any other language?

Right now I use other in a couple of collisions events, and one with event. It's very powerful, but since I never got far enough if python or c#, I'm not sure what the engine is actually checking. For example, it took me a while to understand trigonometry when I was trying to get a line to move away from a point from an angle. I knew I could copy/paste a line and it would work, but in the line used in a tutorial, the "direction" keyword was still used, and I felt I needed to understand that as well. I feel that same way about this exchange of variables. I feel that if given another programming language, I would not know where to begin to achieve this same result without the "other" keyword, which in turn feels like it is making me a less proficient programmer overall.

I can use shortcuts once I understand what is behind them, and since I don't fully understand "other", in a sense that I don't know another way of doing it, I don't feel that I should blindly use it without understanding it.

In a way where if I would ride a bike and not know how it would work. Riding it would be fine, but it would be nice to know at last that it's the peddling that turns the wheels, which makes the bike go wroom.
Read the manual: https://manual.yoyogames.com/#t=GameMaker_Language/GML_Overview/Instance_Keywords.htm&rhsearch=keyword&rhhlterm=keyword

Read the description of 'other' and how to use it.

As a programmer you are expected to use documentation in order to use code that you do not know the implementation of. Either via an engine like GMS or an external library or API. You only need to know the interface and the valid input domains and use cases. The implementation is UNIMPORTANT, unless there are undocumented side effects and bugs. Avoiding or denying this very real expectation WILL make you a bad programmer. Don't reinvent the wheel, don't get distracted, don't get bogged down in details or design that prevent you from completing task.

I would argue you most likely have no clue how any single keyword in GML is implemented or how it works. Why you are focusing on this one I am unsure. Read the documentation and then be productive.

As for how to re-implement 'other' like functionality in different languages... there would be virtually unlimited ways to do so, and even the GML compiler/runner depending on Platform may implement 'other' differently under the hood. GML is a very high level language and its abstraction is INTENTIONAL.

If you want to be a 'good' programmer AND not use the 'other' keyword, then read the documentation of 'other' and imagine a way to implement it, then try to implement it.

I feel like using it is too easy
This is a silly thing to say. Programming any significant piece of software, like a game, is one of the most complex and challenging things a person can do, and you are afraid it is too easy before you have even begun. How about you concentrate on completing a project and then complete it. Afterwards if you feel like you are still interested in not using a keyword like 'other' then you will be more equipped and experienced to achieve that.
 
Last edited:

samspade

Member
Wanting to understand how things work is great. Other is really nothing more than a variable which holds the instance id of the instance that called the with statement (which get tricky when you have imbedded withs) or the collision event. You can easily achieve the same result in a with statement by using local variables as shown by @chamaeleon. If you want to see how it works in action, you can run the program with the debugger and look at the value that other holds.

That said, once you feel you understand it, you should use it. Not using other would actually be bad programming. It would duplicating the work the GameMaker does and provide no benefit to your code, likely making it slower (albeit a trivial amount).
 
I feel like using it is too easy and will make me a bad programmer in the end.

Is there a way to avoid using "other" all together? As an example of what I might be trying to do is, that if a characters variable == something, then do this. However, one might run into problems if there are multiple instances of that same object.
What are you trying to do with your programming?
What is it that your trying to avoid as a problem in your programming?

Those two details would help...
 

saffeine

Member
i think a lot of people are mistaking this post as OP wanting to reinvent the wheel, when really it's OP wanting to understand how the wheel was made, just in case they're in a situation where they're forced to emulate it, such as in another language that doesn't have the convenience of it being a built-in function or variable.
i have no doubt that they're happy to use the keyword once they understand it, even if just for the sake of sating curiosity. maybe they've already picked apart other functions, who knows. it's not that deep.
 
L

LawH

Guest
I think using other is more than just using a variable due to the fact that it entails the use of a collision event, or a with statement. It is in itself a variable, but how you get that variable, and how it happens is the point I'm after.

I don't use the events to control my objects, I like to use code, since it taught me how things are actually written in code. Using these controller events would keep my programming skills at a lower level than actually coding movement etc. myself.

The same is with this. How would you change a variable the same way but without using the keyword other, nor using a collision event. Knowing that will help with opening this problem up.
 
L

LawH

Guest
I love other. Sometimes I type "with (object) { with (other) { " just so I can refer to "object" as "other". Other is the best.
Other really is great, but it doesn't give me any info on how it happens exactly. I think this actually proves my point even more. I know what other does, and I know how great it is. So wouldn't it be great to understand how it actually works.
 
If you want to, you can check it line by line in the debugger (game has to be paused, tho).
Debugger -> All Instances tab -> Local Variables.
"Other" can be used in collisions, with() and structs, and this will reflect on what "other" actually is at that line. Otherwise, as you'll see, .Other will be the same id as .Self.
You can definitely handle collisions and with() statements without it, but at a certain point, you'll probably NEED to have some functions refer to other.variable. Don't demonize a keyword, mate, is all I'm saying
(unless it's from the physics engine, in that case, totally fine)

I don't use the events to control my objects, I like to use code, since it taught me how things are actually written in code. Using these controller events would keep my programming skills at a lower level than actually coding movement etc. myself.
You can store the variable in a local before calling the with()
GML:
var _spd = my_speed;        //Store this before calling with()
with(this_other_guy){
    speed += _spd;
}


//Same thing as
with(this_other_guy){
    speed += other.my_speed;
}
 
Last edited:
L

LawH

Guest
If you want to, you can check it line by line in the debugger (game has to be paused, tho).
Debugger -> All Instances tab -> Local Variables.
"Other" can be used in collisions, with() and structs, and this will reflect on what "other" actually is at that line. Otherwise, as you'll see, .Other will be the same id as .Self.
You can definitely handle collisions and with() statements without it, but at a certain point, you'll probably NEED to have some functions refer to other.variable. Don't demonize a keyword, mate, is all I'm saying
(unless it's from the physics engine, in that case, totally fine)


You can store the variable in a local before calling the with()
GML:
var _spd = my_speed;        //Store this before calling with()
with(this_other_guy){
    speed += _spd;
}


//Same thing as
with(this_other_guy){
    speed += other.my_speed;
}
I already said I like other, and that it works great, so this is again besides the point.

I know how to use other, it's very simple. What I don't understand is how it works. It takes a variable from an instance, and can be used in another instance. Without using other, how would you make this work in the same way as other?
 

chamaeleon

Member
but how you get that variable, and how it happens is the point I'm after.
GMS knows which instance is currently executing code. It stores this id in the essentially global variable other before executing the code block for each matching instance for a with block, and when the with() statement is done, other is reset to its default value (an undefined and undocumented value one should not rely upon at this point in time regardless of what inspection of it may yield).

By definition a collision involves two instances in GMS. One of them is stored in other, while the other instance is the one that executes the collision event code. If both instances are of the same object type, at some point the same step/frame, the two instance will again be involved in a collision event but with the roles reversed, as GMS computes all current collisions and executes code for instances that have a collision event defined.

In all of this heavy work being done under the hood, other is just a variable assignment made before executing the with() block, or one of two instances in the collision process. I assume you realize with() is a kind of shorthand notation for a manual for loop or some matching instances, and collision events could be seen a two nested for loops (but presumably implemented more efficiently) to find pairs of colliding instances. But other itself ... just a single variable assignment.
It takes a variable from an instance
No, it doesn't. with() or the collision event model assigns a value to it. It itself does nothing. It's just a variable.
Without using other, how would you make this work in the same way as other?
Since you're not privy to the source code to GMS, nor can you modify the event model or the with() statement constructs, you cannot. If you mean writing your own for loop over relevant instances and executing some code, just assign id to any variable name you wish before the loop, and you have your "other" equivalent.
 
Without using other, how would you make this work in the same way as other?
...the first example doesn't use it, I literally showed you the exact answer to that... And no, it does not take a variable from an instrance, it takes THE INSTANCE ID (or struct)
 

curato

Member
If you are handling your own collisions then the only time to use other would be with a with statement. If you are using a collision event then other is really handy as it automatically has the id of the other instance in it so that you can change the instance that collided with you. It is actually pretty handy that the engine does the work there and grabs it for you.
 
L

LawH

Guest
As an example, just to clear things up a bit, how would you handle this without the use of other:

I have an object. If any person that is tagged as sentient, gets near it, and they do an action, the object will rotate.
 

woods

Member
obj_person step event
Code:
if (distance_to_object(obj_thing) < 100)
  {
   if (sentient = true) && (keyboard_check_pressed(ord"E"))
  {
obj_thing.image_angle =+ 5;
  }
  }
 
As an example, just to clear things up a bit, how would you handle this without the use of other:

I have an object. If any person that is tagged as sentient, gets near it, and they do an action, the object will rotate.
Judging by this, I'd say your problem is less with understanding other and more to do with understanding instance ID's and how to get them. Frosty has a good post about this: https://forum.yoyogames.com/index.php?threads/whats-the-difference-objects-and-instances.29005/

The number of ways to approach what you asked is pretty high. It depends a lot on how your project works which solution would be best. I would tend to lean towards running code from inside the rotating object and using a with() to loop through the instances of the persons, checking the tags, distance and finally either having a boolean variable that gets set when the player performs an action or checking the keyboard input. But again, the problem you phrased has less to do with other and more to do with generalised ID finding.

I'd also like to point out that while understanding how things work is great, reimplementing GMS functions in a proper project is usually a bad idea as the chance that you write a more optimised and faster version of the in-built function in GML is very low, so the in-built function is almost always going to be faster. Generally, you only want to implement a custom solution if you want different functionality (i.e. writing a custom A* pathfinder that can take tile costs into account, rather than relying on mp_grid functions).
 
Last edited:

Nidoking

Member
I don't use the events to control my objects
Where do you put the code, other than in events? I've heard people speak of this mythical "Game Maker game without using events or instances" before, and nobody's managed to describe how it would be done. More likely, you're using "don't like" as a synonym for "don't understand and can't be bothered to learn, but I assume it's something only small-brained people use, and so I want to figure out the big-brain way to avoid using simple tools that are meant to be used". It's a really antagonistic title you've got for a "please explain to me how this works so I can not use it and do everything the hard way" post.
 
Last edited:
L

LawH

Guest
Where do you put the code, other than in events? I've heard people speak of this mythical "Game Maker game without using events or instances" before, and nobody's managed to describe how it would be done. More likely, you're using "don't like" as a synonym for "don't understand and can't be bothered to learn, but I assume it's something only small-brained people use, and so I want to figure out the big-brain way to avoid using simple tools that are meant to be used". It's a really antagonistic title you've got for a "please explain to me how this works so I can not use it and do everything the hard way" post.
I'm not exactly sure where all this attitude is coming from, but I usually face it when I ask a question from wannabe experts who don't know the answer, so they become angry. If you'd bothered to read anything said here, you could already know that this entire thread was started so that I could learn how something works. It's just the answers are either interesting, or completely irrelevant, like your comment.

I use create events, step events, and draw events, since those are the minimum must if you want to use GMS, but I don't use the control events nor rarely any other events unless there is a specific benefit to it. Like said before, if you use too much of the engines functions, you will not know how anything really works behind the curtain.
 
L

LawH

Guest
Judging by this, I'd say your problem is less with understanding other and more to do with understanding instance ID's and how to get them. Frosty has a good post about this: https://forum.yoyogames.com/index.php?threads/whats-the-difference-objects-and-instances.29005/

The number of ways to approach what you asked is pretty high. It depends a lot on how your project works which solution would be best. I would tend to lean towards running code from inside the rotating object and using a with() to loop through the instances of the persons, checking the tags, distance and finally either having a boolean variable that gets set when the player performs an action or checking the keyboard input. But again, the problem you phrased has less to do with other and more to do with generalised ID finding.

I'd also like to point out that while understanding how things work is great, reimplementing GMS functions in a proper project is usually a bad idea as the chance that you write a more optimised and faster version of the in-built function in GML is very low, so the in-built function is almost always going to be faster. Generally, you only want to implement a custom solution if you want different functionality (i.e. writing a custom A* pathfinder that can take tile costs into account, rather than relying on mp_grid functions).
I figured that one way to sort of do it is to use collision shapes in step events, which in many cases actually works a lot better than the collision event does, so that was something new I learned from this. I'll check that post out as well.

I also learned that collision shapes return the ID of the object, and thus can be used outside collision events. This was really good info.

The only thing I am still wondering is, that if I were to use another more simplified and ready-to-go functionless language, would I have to create these collision areas myself in code, and how would I do that if I were to do it with GMS?

For example if obj_p1.x and y are in an array of coordinates of another object, then somehow I would use that to exchange variables between instances that share the same coordinates.
 
I usually face it when I ask a question from wannabe experts who don't know the answer
Wow. Coming from the guy that made a thread about how to face his top-down player in the joystick direction, this is pretty blunt.

For example if obj_p1.x and y are in an array of coordinates of another object, then somehow I would use that to exchange variables between instances that share the same coordinates.
This is programming 101, you store x, y, and instance ID.
 
L

LawH

Guest
I figured that one way to sort of do it is to use collision shapes in step events, which in many cases actually works a lot better than the collision event does, so that was something new I learned from this. I'll check that post out as well.

I also learned that collision shapes return the ID of the object, and thus can be used outside collision events. This was really good info.

The only thing I am still wondering is, that if I were to use another more simplified and ready-to-go functionless language, would I have to create these collision areas myself in code, and how would I do that if I were to do it with GMS?
Wow. Coming from the guy that made a thread about how to face his top-down player in the joystick direction, this is pretty blunt.


This is programming 101, you store x, y, and instance ID.
Why are you so angry? I never claimed to be an expert, I'm here to learn. What are you here to do? This is a thread on learning about programming, what on earth could make a person angry about that. Just take a look in the mirror and think about whether this is the life you want to live.

This still doesn't answer the deeper question here, which I wouldn't expect from you. The other answers however have been really good, thanks for those!
 
L

LawH

Guest
obj_person step event
Code:
if (distance_to_object(obj_thing) < 100)
  {
   if (sentient = true) && (keyboard_check_pressed(ord"E"))
  {
obj_thing.image_angle =+ 5;
  }
  }
I actually missed this comment completely.

This would not turn all the same objects that are near or even in the whole room, and just turn the one object?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I keep seeing people saying that the keyword other holds an instance ID... this isn't quite right. The keyword other actually holds the value -2 ... this value is then interpreted by the compiler under VERY specific situations as a reference to an instance ID (ie: collision events, or within a with() statement). IIRC, it's actually more efficient to use other than to use any of the different methods outlined here to get an instance ID due to the way GM works internally, and personally I would use it without qualms... GM is a toolbox, and you should use all the tools available if they fulfill the task you need them to.

Just thought I'd add that in, since I'm seeing people say they just want to know how it works. ;)
 

gnysek

Member
it's actually more efficient to use other than to use any of the different methods outlined here to get an instance ID
That's cause no matter what code we gonna use, other will always be set for current event or scope of code if applicable, so if we don't need, we shouldn't waste computing time to get our own variable. It's like invisible line of code before events and with() statements.

Also, as there was mentioned that other is -2, a quick hint about "magical" values in GM:
GML:
self == -1;
other == -2;
all == -3;
noone == -4;
global == -5;
beware then, as instnace_exists(-1) might return true ;)
 

Yal

🐧 *penguin noises*
GMC Elder
I feel like using it is too easy and will make me a bad programmer in the end.

Is there a way to avoid using "other" all together? As an example of what I might be trying to do is, that if a characters variable == something, then do this. However, one might run into problems if there are multiple instances of that same object.
Like 90% of my uses of "other" aren't in collision events, but in with loops:
GML:
number_of_apples = 0
with(obj_apple){
  if(fresh){
    other.number_of_apples++;
  }
}
Try doing something like that without "other". (For simple cases like e.g. a controller object you'll only ever have 1 instance of, you could use the object index, but for things like AI characters that need to consider every other character, and check if they're allied or opposed to them - which you can have an arbitrary number of - there's no way to refer back out from a with loop without "other")
 
Z

zendraw

Guest
other has its use, if you dont want to use it becouse some superficial belief of yours you wont become a better programmer anyway. being good at somthing is understanding the thing fully, if you block one part of it how do you expect to become better. giving attention only to sympathical comments wont help your case.

i avoid using other but i know why and ive had problems with it. and game maker allows you to avoid it easily. you havent faced a problem and never understand how to deal with the situation since you avoid it.

this is not a programming topic, its an offtopic.
 

Karlstens

Member
I feel like using it is too easy and will make me a bad programmer in the end.
No. I say that the reverse is true, and not using it will make you bad at programming GML. Why not have the attitude of embracing it? Use the heck out of it, get to know it, understand its use and purpose.

You “feel” like using it is too easy, so go on then, use it, I challenge you to.

Also, I don’t think you realise, but the way you’re engaging others is fairly off putting and I dare say rude. It’s a quick way to get blocked by some really intelligent people that would otherwise continue to help you through your game making journey - it pays to be polite my dude.
 
Z

zendraw

Guest
Programming is all about picking the easiest option. If picking the hardest option made us better programmers, we'd still be writing machine bytecode by hand and run it on electron-tube mainframes.
thats not what programming is all about. programming is about manipulating data in an efficient way. the easyest way to check somthing is to write an if (whatever) {} butif you go on writing ifs youll go crazy eventually. everything has its purpose and thats what the programming must understand if he is learning and must practice.
 
Top