I don't like using "other" keyword

TsukaYuriko

☄️
Forum Staff
Moderator
Guys, we've gone from talking about how other works to discussing what the point of this topic is and now to what the point of programming is... it's great that we cleared up what the topic is about - learning about how other works - so now let's stick to that topic. :)

Also, there's no need to fight about who's being rude to whom. There were some misunderstandings of intent at the start of the topic, nobody was initially angry at anyone, and nobody should be pointing fingers or attacking anyone. Let's all take it down a notch, acknowledge what may not have gone the best way it could have and move on.
 
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?
Yes, indeed you would have to create those collisions yourself. Everything you use in programming, in any language, has been created by someone using maths. If you want a collision, you figure out what shapes you are colliding (rectangles are generally the fastest and easiest to work with, which is why they are a common collision mask) and then you do the maths to figure out whether those shapes are overlapping. That's all a collision is, there's no "special collision quality" that separates it from the mathematics of geometry. If you wanted to do it in GMS, you would do exactly that. Use the coordinates of the instance combined with whatever collision mask you are using (so probably using the bbox_* variables) and then doing the maths to see if those coordinates intersect with other coordinates from other instances. other only has an in-built relation to collision if used specifically inside a Collision Event, it's not inherently tied to collision.

I don't know where you are in your programming journey, but when I was at the start of mine, I lacked a..."cohesive" map of what programming was in my head. Things like the fact that setting hspeed in GMS was literally just doing x +- some number didn't fully click for a while. It made some things seem more confusing and "magical" than they actually were and it led to me thinking of a lot of things as black boxes that I couldn't replicate when, in fact, I could have replicated them easily. Getting past that point was a pretty big reveal in programming terms to me and it made a lot of things (like other) make way more sense after I'd started to piece together the map of programming better.
 

Kezarus

Endless Game Maker
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.
I wasn't going to say anything... but I was about to answer your question and saw your replies... I simply gave up. There are people with a decade of experience here trying to help you, mate. No need to be rude. Take a deep breath, calm down and you will have all answers.

I know I did, time and time again when I needed this forum. =]

About the "other" keyword. If you are handling collisions in the step event, looping all instances with instance_find, then maybe you don't need "other" in those cases. But if you use a with() loop and collision events then it's very hard not to.

"other" simply returns you an ID reference under the hood (like Nocturne said). There is a bunch of examples above in the Collision Event and with() loop that uses it.

Have fun deving you games, mate! =]


Cheers!
 

woods

Member
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.

obj_person step event

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?

that wasnt the perimeters of your querry ;o)




but looking back to your original post.. the first line..
I feel like using it is too easy and will make me a bad programmer in the end.

using the tools available to get the job done. does not make you a bad programmer... would you use a hammer or a wrench to drive a nail? ... they both could work, but one takes more work to get the same results.


you know what "other" does and how to use it.. you've said that plenty already.
there is no "deep understanding" of how it works.
its pretty cut and dry.. it hold a value of a thing that is being worked with in the code that is not calling the script... its not one of those "magic number things" but it does simply just "work" with the ID of the other object you are interacting with..


watching this thread degrade and unfold, it looks like its turning into one of those "bitching to b*tch" scenarios
 
Last edited:

Gizmo199

Member
Wow, what a read! haha. Yeah, I guess my thinking is, I get wanting to learn how the insides work, but honestly (been using gm since 2006) it comes in due time. Actually, using it will help you learn exactly how it works. Otherwise (I've done this exact thing) you will spend the next 6 months researching how to make a cog and still not know how a clock works. haha. It's a fun challenge I suppose, but if you just focus on actually making games first, the rest will come. I can guarantee you will run into a situation where you WILL have to find a way around "other", by that point though, you will have a firm grasp on the concept and learned so many other skills that you won't think twice about "how its implemented". Either way, do you, and have fun doing it!

I think overall this is quite an un-important hill to die on for either side. haha. :p
 

Kezarus

Endless Game Maker
@Yal, holy molly, I'm using it since 2006 (like @Gizmo199) and I'm still learning a lot from you guys. =]

The "other" keyword can be confusing as this is doesn't exists in other languages. Same for the with() loop. Make a lot of sense in GML though.

@LawH, do you have material enough to get where you want to be? You can go without using other on some specific cases, yes. And "other" will call internally the "caller of a function" for collisions events and with() loops. If you have anyother points to clarify we are here to help. If you want to not use "other", it's somewhat hard and counter-productively, but it's doable (in some cases). But it's NOT a bad practice and using "other" doesn't make you a bad programmer. =]

Cheers!
 

Yal

🐧 *penguin noises*
GMC Elder
The "other" keyword can be confusing as this is doesn't exists in other languages.
C++ has this and other for operator definitions (i.e. redefining what + does for your special object) so it exists in at least one other language:
Screenshot from 2021-02-23 17-56-20.png
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I think this topic has run it's course... but I won't close the topic just yet in case the OP has anything further they wish to add or ask about. So, please, let's not get off topic and let the OP have time to read through all the replies here and reply themselves... Tbh, I think it's been really interesting to see how passionate some of you have been discussing the merits of the other keyword! Why not direct that passion to helping some of the unanswered question in the QA and Support forums? :p

Seriously though, I think it's GREAT that anyone wants to expand their understanding of both GameMaker and Programming in general! However, I would also say that avoiding any of the built-in functionality supplied by ANY product is usually not a good idea. Sure, it's FUN to work around things and do it yourself - like learning basic trigonometry and using that instead of the lengthdir_x/y functions - and all that you learn can and will be applied at some point in your programming future... But probably not in the same places where you can use built-in functionality like other. Most things like this are more efficient than any workaround, and generally lend themselves to cleaner and more organised code, which is a large part of being a "good" programmer. :)
 

Kezarus

Endless Game Maker
C++ has this and other for operator definitions (i.e. redefining what + does for your special object) so it exists in at least one other language:
Ohou, I didn't know that! In Java/C#/SQL "other" doesn't exist.

Let me rephrase to "other keyword doesn't exists in other languages (that I'm proficient with)". XD
 
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.
So true (well, let's say working and logical option).
Programming is problem solving and problem simplification waaaay more than typing. This is not glamorous at all, loll 😂


I think this topic has run it's course...
Yes, we will all settle this like real men (and women) this week-end for the Big JAM!! 🤡
 
Last edited:

Gizmo199

Member
I think this topic has run it's course... but I won't close the topic just yet in case the OP has anything further they wish to add or ask about. So, please, let's not get off topic and let the OP have time to read through all the replies here and reply themselves... Tbh, I think it's been really interesting to see how passionate some of you have been discussing the merits of the other keyword! Why not direct that passion to helping some of the unanswered question in the QA and Support forums? :p

Seriously though, I think it's GREAT that anyone wants to expand their understanding of both GameMaker and Programming in general! However, I would also say that avoiding any of the built-in functionality supplied by ANY product is usually not a good idea. Sure, it's FUN to work around things and do it yourself - like learning basic trigonometry and using that instead of the lengthdir_x/y functions - and all that you learn can and will be applied at some point in your programming future... But probably not in the same places where you can use built-in functionality like other. Most things like this are more efficient than any workaround, and generally lend themselves to cleaner and more organised code, which is a large part of being a "good" programmer. :)
That is a perfect example actually @Nocturne ! Been using lengthdir_x/y FOREVER. Once I got into 3d I was like "crap I need to learn trig" then it hit me...this is just exactly how lengthdir_x/y works. Because I used the built in functionality I didn't have to think twice about it. :) anywho I'm done now! Enjoy your journey OP.
 

Shut

Member
I've got another solution for you all if you just hate the word other for some reason.

GML:
#macro another other
I don't think there's anything wrong with trying to understand how the engine works or what @LawH was asking for.. so to keep this simple and point you to the right direction:

Just write your own function, if it's collision related use instance ids (keep 2 variables that save both colliding instances and name them however you want and switch between them depending on your needs)

as for with - you could do something similar

GML:
var _id = id; // set calling instance id
with(obj_Other) { show_message(string(_id)); }
however I do agree with OTHERS :rolleyes: that if you plan to use GM, there's no need to make things harder as it's much more efficient to use other.
 
Last edited:

Gizmo199

Member
#macro another other
GML:
#macro O collision_rectangle
#macro T (
#macro H bbox_left, bbox_top, bbox_right, bbox_bottom
#macro E , other, false, true
#macro R )

with ( O T H E R ){
    instance_destroy();
}
NVM, this actually doesn't compile. lol. Edited with some correct stuff below. :p
EDIT: (forgot you have to include the brackets with the function call or it won't compile)
GML:
#macro O collision_rectangle(
#macro T bbox_left, bbox_top,
#macro H bbox_right, bbox_bottom,
#macro E other, false, true
#macro R )

with ( O T H E R ){
    instance_destroy();
}
GML:
#macro O show_message(
#macro T "Hello " +
#macro H "Who is other?" +
#macro E " Its: "+string(object_get_name(other.object_index))
#macro R )

O T H E R;
you can also re-define constants using macros:
GML:
#macro other show_message("I used to be a constant, now I'm a message");
other;
sorry I couldn't resist. I promise I'm done now. lol.
 
Last edited:

Rob

Member
The keyword other contains an instance_id. What is an instance_id? You can have 100 instances of a single object, so each instance gets its own "number" to differentiate itself from the others.

There are quite a few functions that you can use in place of other, that return an instance_id. Some examples are collision_point, collision_circle, instance_place. Other functions will give you a list of instance_id's, so that you can check for collision with multiple instances at the same time such as collision_line_list.

Like Yal, I tend to use other inside of a loop, because the scope of the code has changed to a different object, but I'm running the code from the other's event.

eg

GML:
//Create event of obj_one
something = 10;

with obj_two{
   //The scope has now changed to each instance of obj_two in turn.
   my_stat = other.something;
}

//An alternative to this is
//Create event of obj_one
var something = 10;

with obj_two{
   //You can reference local variables inside a with loop, even though the scope of the code has changed
   my_stat = something;
}
It's good to want to know stuff. Don't overthink it too much, and just know that things will make sense to you eventually, the more you use gamemaker.

I always find the manual useful for giving code examples, and sometimes I will just copy/paste that code if I don't need to do much (mainly the tilemap_get functions). If you want to learn/understand more, and if you aren't already, visiting the manual to see how to use a function and what it returns is really useful.

Some advice that I read that I took on board and I feel has helped me, is to at least check out what functions gamemaker does via the manual. Even though you probably won't understand all of it, some seeds will be planted, and when you come to try to do something, you may have an idea that there's a function out there that will save you a lot of time and headache. You can also use gamemaker auto-complete to show you possible functions you might want just by typing "draw_" as a line of code for example.

This, along with the ability to understand error messages, is the path to victory!
 
Last edited:

poliver

Member
Unless you're programming in assembly(even then it's debatable considering different chipsets) you'll be using language/framework/environment specific functions to get the job done.
Purposefully trying to avoid that and only using stuff that's somehow general to ALL programming languages sounds extremely limiting.

PS If you know how 'other' behaves you can recreate it from basics in other environments.
 

saffeine

Member
PS If you know how 'other' behaves you can recreate it from basics in other environments.
i think this was actually the point of the post to begin with.

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 is missing the point a little. I am using the other keyword, but I would like to know how the function works.
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.

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.
it's less about whether OP knows what other does, and more that they want to learn how it works on a technical level.
if they were to use another engine without the keyword, they'd probably need to understand how to get the value of other for certain things.

i think a lot of this thread has devolved into repetition in that everyone is suggesting how to use other, rather than how to recreate it outside of gamemaker.
i'm almost sure that somewhere in the posts there was another example of lengthdir_ functions and what the math is behind them, which was crucial to learn for using another environment myself, even if i'm more than comfortable using them in gamemaker which, given that it's my primary environment for game dev, is usually the case.
for as long as someone uses gamemaker, the built-in functions are a no-brainer, but i don't fault anyone for wanting to understand them behind the scenes so that they can apply them elsewhere.
 
Top