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

Problem with events working is different instance of the object

HI !
I have a problem with my project, i have this Left Down event:
1638825371246.png
but this event is working only in one of the istances of my project, and not in all of them.

the objective here is turn off the obj_camera_s with the variable enabled, but i want turn off the especific camera i click.
and this is not working, is working only in one instance of the cameras.

someone can help me ?
 

ThraxxMedia

Member
Hello there :)

First things first: if I were you, I'd implement some sort of check to see whether or not the "obj_buttonCamera" (and others that you reference directly via dot notation) actually exists - you wouldn't believe how many times errors may occur simply because an instance happens to not be there. Secondly: someone correct me if I'm mistaken, but as far as I know, referencing an object like you did in the IF-statement only touches / checks the very first instance of that specific object index found, but doesn't continue afterwards. If you wanted to run the code for all instances of "obj_buttonCamera" you'd have to do something like this:

GML:
with (obj_buttonCamera)
{
    if (skillActivated)
    {
        skillActivated = false;
        other.enabled = false;
        
        if (myNetworkManager.playerIndex == 2)
        {
            buffer_seek(obj_client.client_buffer, buffer_seek_start, 0);
            buffer_write(obj_client.client_buffer, buffer_bool, 1);
            buffer_write(obj_client.client_buffer, buffer_bool, other.enabled);
            network_send_packet(obj_client.client, obj_client.client_buffer, buffer_tell(obj_client.client_buffer));
        }
    }
}
Please note that the "with"-statement already includes a check to see if an object of that type exists, so you don't need it here. If no "obj_buttonCamera" is found, the above code would do nothing and be skipped entirely.

Cheers,
~Thraxx
 
Top