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

Networking Help

S

Supereor

Guest
Hey all am working on a more than 1 client game and i got 2 clients able to move their own player on the server now I'm trying to get it where on the clients screen you can see the other players. I got a start to it but I'm getting a variable error ill address later in this post
Code:
This is in the receive packets script in the case that handles the player movement, I'm moving them on the server then sending their X and Y to the other players.

case 2: //Movement
        var playerident = buffer_read(buffer, buffer_u32);
        var xx = buffer_read(buffer, buffer_u32);
        var yy = buffer_read(buffer, buffer_u32);
        with(obj_block)
        {
            if(playerid == playerident)
            {
                x = xx //X
                y = yy //Y
            }
        }
            with(obj_block)
            {
                if(sock != socket)
                {
                    buffer_seek(global.buffer, buffer_seek_start, 0);
                    buffer_write(global.buffer, buffer_u8, 2);
                    buffer_write(global.buffer, buffer_u32, playerident); //His G.P
                    buffer_write(global.buffer, buffer_u32, xx); //His X
                    buffer_write(global.buffer, buffer_u32, yy); //His Y
                    network_send_packet(sock, global.buffer, buffer_tell(global.buffer));
                }
            }
            
    break;
Then on the Client side this what happens when they get this packet

Code:
case 2: //Getting someone elses movement
        gip = buffer_read(buffer, buffer_u32);
        if(instance_exists(obj_remoteplayer))
        {
            with(obj_remoteplayer)
            {
                if(globplayerid == gip)
                {
                    x = buffer_read(buffer, buffer_u32);
                    y = buffer_read(buffer, buffer_u32);
                }
            }
        }else
        {
            instance_create(30,30,obj_remoteplayer);
            with(obj_remoteplayer)
            {
                globplayerid = gip;
                x = buffer_read(buffer, buffer_u32);
                y = buffer_read(buffer, buffer_u32);
            }
        }
Yes i know this code only works with 2 players and I'm just trying to figure that out first then move on to having more than 2. When i run the client and try to move it says the variable globplayerid isn't set before reading it, but in the remoteplayer create i put it there. So i don't know why I'm getting this error

Variable obj_remoteplayer.gip(100002, -2147483648) not set before reading it.
at gml_Script_scr_received_packet (line 29) - globplayerid = gip;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_received_packet (line 29)
called from - gml_Object_obj_client_NetworkingEvent_1 (line 9) - scr_received_packet(buffer);

Can anyone help me?
 
The error message is pointing to the "gip" variable not being defined.

You need to put other.gip because you are trying to reference it inside a with{} statement and you have defined gip outside the with{} statement
 
Last edited:
Top