• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED How to detect if an object is outside of the room ?

First, thanks a lot for taking the time to read and help. I try beforehand to read the documentation and solve it by myself. Disclaimer for grammar : English is not my first language :)

There is an object that can go far from the player sprite.
Sometimes it can go out of the camera and the room. (room and camera are, most of the time the same size).

How do I detect that this object is out of the room. And then use a timer for this object being outside.

I have looked at the documentation, I know wrap to make an object go out.
I have tried in the step event object the following code :
And I have tried in the event "Outside Room" with the second block of code :
Note, in the create event of the object, i declare


GML:
if(place_meeting(x,y,room)){
    time_help_message1 += 1;
    if (time_help_message1 >= 3*60){
        draw_text(room_width/2, room_height/2+100, "Push 'R' to restart level");
    }  
    else if (keyboard_check_pressed(ord("R"))){
        time_help_message1 = 0;
    }
}

GML:
// in the create event:
time_help_message1 = 0; // timer for when object is outside


// In the OUTSIDE ROOM Event
time_help_message1 += 1;
   
if (time_help_message1 >= 2*60){
    draw_text(room_width/2, room_height/2+100, "Push 'R' to restart level");
}  
else if (keyboard_check_pressed(ord("R"))){
    time_help_message1 = 0;
}

I get the following error message when in-game, the object move outside the room with the event "outside room" :
And even if the variable is declare in create, it seems not to find it. Either, I am doing something wrong, either the outside room is not a good friend.
Either way, it might be better to have the outside room information not in the event outside room

Code:
############################################################################################
FATAL ERROR in
action number 1
of Other Event: Outside Room
for object obj_rotation:

Variable box_around_player_not_auto.time_help_message1(100007, -2147483648) not set before reading it.
at gml_Object_obj_rotation_Other_0 (line 4) - time_help_message1 += 1;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_rotation_Other_0 (line 4)
 

Petrik33

Member
Guess you have a with statement somewhere and there you haven't marked the variable other.variable if so, write some more info about the box around player not auto object, if it's false I don't how to help you my friend, sorry.
 
Thanks Petrik33 and TheouAegis for your two answers.

@Petrik33
I checked variable and change it to a name that exists nowhere else. This didn't solve anything. There might be a bug here or a logic Idon't get.

@TheouAegis, didn't knew the collision box exist or not depending on-screen position. It's very useful and it worked like a charm I loved it.

So, I left the event "outside room". Tried the same in step event, also didn't work.
But it does work in the Draw Gui event. So, it works fine for now.


Thanks for the help.
 

TheouAegis

Member
If you are trying to draw something, it needs to be in the Draw or GUI event. But as for just incrementing a variable, that should be in the step event or end step event.

The outside room event doesn't work because it only is executed when the instance goes from being inside the room to outside the room. So if the instancr stays outside the room, the event will not fire again. Same with the outside view event.
 
Hi TheouAegis,

Very clear explanation. It helps to understand how to use the event and how they work. It made me read the documentation on the event.
Thanks a lot for your help :)
 
Top