Find instance that called a script?

G

GerPronouncedGrr

Guest
As the title says, I'm wondering if GMS provides a method to return the calling instance of a script. For example, say I have 2 players, and each uses the same generic HP control script. For any call to that script, how can I find out which player object initiated that call?

BTW, I'm currently using GMS2, but asking here because I can't find the answer in the documentation for either version, so I don't want to clutter up the GMS2 beta forum needlessly. I am happy to have this thread moved if it belongs in the beta forum instead.
 

Alexx

Member
You probably won't even need it. Not sure yet about GMS2 as haven't delved in that far as yet, but with 1.4 you can send through id as an argument, if really required.
 
Last edited:

YoSniper

Member
The object calling a script can be found by simply referencing "self" or "id" within said script.

Beware, though. If you call a script within a script, the original calling instance is still referenced by such keywords.
 
G

GerPronouncedGrr

Guest
Ok, this is good info. Thanks very much, both of you!
 
G

GerPronouncedGrr

Guest
Ah, interesting. When I called up the documentation for 'self' in GMS2 I learned that it is now deprecated in favour of other keywords. But still, I appreciated being helped alone to the answer :)
 
So this old but if you have a script and want to not create two separate scripts, while having slightly different things for each, object in the script use object_index to check what Object is running the code.

if(object_index==Object1){image_alpha=0.5;}
if(object_index==Object2){image_alpha=0.5;}
 
Top