• 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!

object find problem with deactivating objects

zampa

Member
So i am trying to check if i want to activate or deactivate objects every 30 frames
with this code:
GML:
count_activate++;

if(count_activate >= 30){
    count_activate = 0;
    var right = x + global.iw/2 + 180;
    var left = x - global.iw/2 - 180;
    var top = y - global.ih/2 - 180;
    var bottom = y + global.ih/2 + 180;
    instance_activate_object(obj_platform_falling);
    
    var num = instance_number(obj_platform_falling);
    if(num != 0){
        for(var i = 0; i < num; i ++){
            var inst = instance_find(obj_platform_falling,i);
            if(inst != -4){
                if(!point_in_rectangle(inst.x,inst.y,left,top,right,bottom)){
                    instance_deactivate_object(inst);
                }
            }
        }
    }
}
but it doesn't deactivate them all
I tried putting 4 objects in the room and the running a instance_number for that objects and it tells me that 2 are active even if they should be all deactivated
so i ran the debugger on that part and i found out that var num = instance_number(obj_platform_falling); this variables returns 4,
the correct number of objects, but with instance_find when i is 2 it returns -4 like the second object doesn't even exist

I don't know what to do
 

Simon Gust

Member
Pretty sure activation / deactivation is laid out over multiple steps (2 I guess), so not all instances are active the time you're calling them.
Try deactivating them on count_activate == 3 or something, just to be safe.
 

zampa

Member
Pretty sure activation / deactivation is laid out over multiple steps (2 I guess), so not all instances are active the time you're calling them.
Try deactivating them on count_activate == 3 or something, just to be safe.
i already tried that but it didn't work :/

but i was messing around and i think i found another way
GML:
if(count_activate >= 30){
    count_activate = 0;
    var right = x + global.iw/2 + 180;
    var left = x - global.iw/2 - 180;
    var top = y - global.ih/2 - 180;
    var bottom = y + global.ih/2 + 180;
    instance_activate_object(obj_platform_falling);
    
    with(obj_platform_falling){
        if(!point_in_rectangle(x,y,left,top,right,bottom)){
            instance_deactivate_object(id);
        }
    }   
}
this for some reason works

is this a good solution?
 

Simon Gust

Member
i already tried that but it didn't work :/

but i was messing around and i think i found another way
GML:
if(count_activate >= 30){
    count_activate = 0;
    var right = x + global.iw/2 + 180;
    var left = x - global.iw/2 - 180;
    var top = y - global.ih/2 - 180;
    var bottom = y + global.ih/2 + 180;
    instance_activate_object(obj_platform_falling);
   
    with(obj_platform_falling){
        if(!point_in_rectangle(x,y,left,top,right,bottom)){
            instance_deactivate_object(id);
        }
    }  
}
this for some reason works

is this a good solution?
Yes, this is fine.
 
Top