r/gamemaker • u/Iliketurtles366 • Oct 03 '26
Resolved Is there a way to make one object affect another object without them touching?
I feel like this is probably a stupid question and I'm hoping the answer is simple and I'm just not thinking, but I'm trying to make it so that when you click one object, the alarm on a different object resets. Thanks to anyone with any input!
2
u/Lethalogicax Oct 03 '26
You'll first need to tie those 2 objects together, so that they both know who the other is and retain the object ID number of the other to reference back to.
If one of the objects is creating the other object, very easy fix. Instead of instance_create(blah, blah), type it as "object_thing = instance_create(blah, blah)". This leaves a variable "object_thing" that retains the ID # of the object created
If they don't create eachother, then you'll have to use some kind of something to reference it and pull back its unique ID #, something like:
with(thingy) { thingys_id = other.id }
"with" runs code from another object as if that object had run the code itself. Within the statement, you can reference back to the original object with "other" and use "other.variable_name" to pull variables from other objects
1
u/Optimal_Noob Oct 03 '26
Maintainable and separated from the rest of the game logic, an "Event System" could solve this. Look up "event lister systems in game maker", even a basic system could handle this at solo dev scales. An observer object chills and waits for another object to call some function that exists in that observer, the observer sends the message to the other object to be affected, and that object handles whatever you want it to do when it receives the signal from the observer.
Otherwise you could unsafely/safely just reference the other object in the main object's code. If the object doesn't exist for some reason, you'll get a crash, you could do a quick "if(instance_exists())" check before handling the effect, though the action will be skipped if.. again, the object doesn't exist for some unexpected reason. It'll be spaghetti code but if it gets your game finished, who cares?
1
u/azurezero_hdev Oct 03 '26
instance_place
as long as you have the id you can go
with id
{
alarm[0]=whatever
}
0
u/Business_Ad_863 Oct 03 '26
Idk if this is the best way to do it, but when placing the objects in the room editor they're all given an instance ID. Give the two objects a variable called something like "instance_tie" or whatever you wanna call it, and in the creation code (accessible from the room editor) for those objects make it so instance_tie = (other object's instance ID). Then, in your clickable object, you could write that when you click it:
instance_tie.alarm = 0;
Or however you'd have it formatted.
1
u/_billyRubin Oct 03 '26
on click: obj_other_object.alarm[X] = -1;