Second client crash in multiplayer

I can't figure out why the second client on the server doesn't get the data in the buffer. Error: illegal undefined/null use
I'm trying to query the coordinates and status of the player
GML:
//Update x,y and player state
buffer_seek(con_client.client_buffer,buffer_seek_start,0);
buffer_write(con_client.client_buffer,buffer_u8,network.player_sync);
network_send_packet(con_client.client,con_client.client_buffer,buffer_tell(con_client.client_buffer));
GML:
case network.player_sync:
        var _player = ds_map_find_value(socket_to_instanceid,socket)
        
        var i = 0;
        repeat(ds_list_size(socket_list))
        {
            var _sock = ds_list_find_value(socket_list,i)
            
            buffer_seek(server_buffer,buffer_seek_start,0);
            buffer_write(server_buffer,buffer_u8,network.player_sync);
            buffer_write(server_buffer,buffer_u8,socket);
            buffer_write(server_buffer,buffer_u16,_player.x);
            buffer_write(server_buffer,buffer_u16,_player.y);
            buffer_write(server_buffer,buffer_u8,_player.state);
            network_send_packet(_sock,server_buffer,buffer_tell(server_buffer));
            
            i++
        }
        break;


GML:
case network.player_sync:
        var _sock = buffer_read(buffer,buffer_u8);
        var xx = buffer_read(buffer,buffer_u16);
        var yy = buffer_read(buffer,buffer_u16);
        var _state = buffer_read(buffer,buffer_u8);
        
        _player = ds_map_find_value(socket_to_instanceid,_sock);
        _player.x = xx
        _player.y = yy
        _player.state = _state
        break;
 

Jman

Member
I think it would help if you set a break point then used the debugger to step through the "case network.player_sync:" code. I'm guessing
you'll find there could be something going wrong with the "ds_map_find_value" line of code, but I could be wrong. If you use the debugger
you'll be able to figure out which exact line of code is causing the problem.
 
I think it would help if you set a break point then used the debugger to step through the "case network.player_sync:" code. I'm guessing
you'll find there could be something going wrong with the "ds_map_find_value" line of code, but I could be wrong. If you use the debugger
you'll be able to figure out which exact line of code is causing the problem.
I'm running the second client with executeshell and I can't track it in debugger.
 

Jman

Member
It would be ideal if you could run the second client in GMS2 to make use of the debugger, but if not
you could use break statements or comments to figure out which line is causing the problem. Or was
"Error: illegal undefined/null use " the only error info it gave you?
 
It would be ideal if you could run the second client in GMS2 to make use of the debugger, but if not
you could use break statements or comments to figure out which line is causing the problem. Or was
"Error: illegal undefined/null use " the only error info it gave you?
_player.x = xx, error in apply data if i swapping xx with yy or state, i get the same error.
 

Jman

Member
I'm assuming you are using TCP and my TCP knowledge is rusty so you can correct me on anything that is wrong.
Okay, here is what I think is happening. According to the docs ds_map_find_value() returns undefined when you give it a key
that doesn't exist. "If no such key exists then the function will return <undefined> ". I think you are getting an undefined value
because the socket ids that you get from network_create_socket() and when a socket connects won't be consistent a crossed the different clients and server.
Because of this the client that receives the packet will have the associated the other client with a different number than the server. This leads to its ds_map
containing a different key value then what value is sent to it in the packet(and according to the docs results in an undefined value). When you try to modify
an undefined value like it is an instance you get the error that is occurring. I would try changing your game to use a more consistent way of identifying each
client that doesn't rely on socket values. Let me know if that does or doesn't work.
 
Top