Legacy GM detecting objects in seperate rooms?

M

mst3kdavid

Guest
I'm wanting to check and see if there is an object already at a (x,y) position. Is there a way to do this when in a different room? I can provide some of my code to help with the context if need be/if asked but I don't see the necessity in that.

Would it be more effective to use a global variable/array or is there a more direct/efficient way to detect objects positions in different rooms. I've tried several attempts on this but haven't been successful, yet.
 
J

jb skaggs

Guest
I assume you are referring to a room that is persistant?
 

CloseRange

Member
well first of all the room or the object would have to persistant (otherwise all memory of it is lost as soon as you leave the room) you would want to also set a variable for the object based on what room it is in (You can only check your current room and not the room of another object) so in the create event of the object just say:
Code:
rm = room;
and then use a with check to look for an object
Code:
with (your_object_here) {
     if rm == rm_to_check && x == value && y == value {
         // do stuff
     }
}
 
M

mst3kdavid

Guest
well first of all the room or the object would have to persistant (otherwise all memory of it is lost as soon as you leave the room) you would want to also set a variable for the object based on what room it is in (You can only check your current room and not the room of another object) so in the create event of the object just say:
Code:
rm = room;
and then use a with check to look for an object
Code:
with (your_object_here) {
     if rm == rm_to_check && x == value && y == value {
         // do stuff
     }
}
would I have to be in the room the object is in for it to work?
 
M

mst3kdavid

Guest
as long as the object or room is persistant I don't think so
ok my objects are not persistent unless they are selected and ready to be moved to another room. all my rooms are persistent all the time.
global.objectinthatroom is set up in my global var handler.

if global.objectinthatroom=0 and there is a key press it will permit a room change on obj_red_hexagon to that perspective room assigned to that key.

Code:
var myredhexagon=id;
if selected=1
    {
    with (obj_green_hexagon) {
        if rm == rm_layer2 && x == myredhexagon.x && y == myredhexagon.y {
            global.objectinthatroom=1
        }
    }
}
it let me move to that room even though there was an object in that room with the same (x,y) position
 
M

mst3kdavid

Guest
to clarify it is not changing the global.objectinthatroom to equal 1. tested it with a show message
 

CloseRange

Member
you're using a temp variable to check the condition, instead try removing the "var" or taking out that variable and using other.x and other.y instead
 
Top