Jump to content


Photo

Network NPC sync issue

gm:studio

Best Answer tommah, 26 January 2016 - 02:49 PM

So I changed all the buffer types from "buffer_u32" to "buffer_u16" and it seems to be working mostly like it should, although the NPCs on the client side are blinking and the fps nosedive is still there.

 

*Edit*

Fixed it:

        var Enemyfind=-1;
        var InsNo=instance_number(slave_dummy);
        var NetIndex=buffer_read(buffer,buffer_u16);
        for(i=0;i<InsNo;i+=1){ //this was the difference
            var Ins=instance_find(slave_dummy,i);
            if Ins.index=NetIndex{
                Ins.x=buffer_read(buffer,buffer_u16);
                Ins.y=buffer_read(buffer,buffer_u16);
                Ins.sprite_index=buffer_read(buffer,buffer_u16);
                Ins.image_index=buffer_read(buffer,buffer_u16);
                Ins.isalive=buffer_read(buffer,buffer_u16);
                Enemyfind=1
            }
            if Enemyfind=1 break;
        }
        if Enemyfind=-1{
            var xx=buffer_read(buffer,buffer_u16);
            var yy=buffer_read(buffer,buffer_u16);
            var spr=buffer_read(buffer,buffer_u16);
            SlaveNPC=instance_create(xx,yy,slave_dummy);
            SlaveNPC.sprite_index=spr
            SlaveNPC.index=NetIndex;
            SlaveNPC.NetKill=false;
        }

After getting the sprite_index to work by changing to buffer type to "buffer_u16", I wrote this for loops instead of using "with".  Fixed all problems, even the FPS drop issue.

Go to the full post


  • This topic is locked This topic is locked
5 replies to this topic

#1 tommah

tommah

    GMC Member

  • GMC Member
  • 275 posts
  • Version:GM:Studio

Posted 24 January 2016 - 08:03 PM

I'm making online co-op in my game and I'm having a problem with Network Synchronizing.  I want to start by say I have one Host/Server player and one Client player and they work perfectly, all sprites/coordinates/actions all line up perfectly.

 

I have never done Networking before.

 

I started to try syncing NPCs (both bad and good) and it started great, I'm using a "slave" enemy for the client and coordinates are perfect.  But when I started to send ANYTHING else its like they aren't receiving the data.

 

Here is the Host Send code:

//Send
with test_dummy{ //name of parent npc so it loops through all npcs
    buffer_seek( other.buffer , buffer_seek_start , 0 );
    buffer_write( other.buffer , buffer_u8 , 2 ); //data identity
    buffer_write( other.buffer , buffer_u32 , id );//specific ID
    buffer_write( other.buffer , buffer_u32 , x ); //location
    buffer_write( other.buffer , buffer_u32 , y );
    buffer_write( other.buffer , buffer_u32 , sprite_index);
    network_send_packet(other.socket,other.buffer,buffer_tell(other.buffer));  
}

Client Receive code:

        var Enemyfind=-1;
        NetIndex=buffer_read(buffer,buffer_u32); //read specific ID
        with slave_dummy{ //with Client Slave
            if index=other.NetIndex{ //if index=specific ID then sync
                x=buffer_read(other.buffer,buffer_u32);
                y=buffer_read(other.buffer,buffer_u32);
                sprite_index=buffer_read(other.buffer,buffer_u32);
                other.Enemyfind=1 //change to 1
            }
        }
        if Enemyfind=-1{ //if STILL -1 then create a slave dummy
            var xx=buffer_read(buffer,buffer_u32);
            var yy=buffer_read(buffer,buffer_u32);
            SlaveNPC=instance_create(xx,yy,slave_dummy);
            SlaveNPC.index=NetIndex; //give this instance the NetIndex ID
        }

I would almost everything not work because then at least I know to start at the beginning to get it to work.  But I can't figure out why the ID,the x, and the y get passed on, and STAY synced no matter what, but everything I've tried after that doesn't get sent/received.

 

The only thing I could think of is that I was trying to send parent information.  But the id's were still the same and shouldn't the childs variables still be sent?

 

Here's a picture of what I mean.  The Green squares are the slave_dummies that are supposed to receive the information and change "sprite_index".  id, x, and y all stay up to date but nothing else.

957ae49556f70f295afc4e0b08917825.png

 

As I said I'm new to Networking, but not GM: Studio. This also seems to be a resource heavy way about doing this as after about 20 seconds the client framerate starts nosediving (slave_dummy Send/receive being the cause, I checked).  Any tips would be appreciated on this as well.


Edited by tommah, 24 January 2016 - 08:11 PM.

  • 0

#2 Strawbry_Jam

Strawbry_Jam

    Likes Toast

  • GMC Member
  • 345 posts
  • Version:Unknown

Posted 25 January 2016 - 02:43 AM

I'd start with outputing the buffer data so you see exactly what you are sending and receiving instead of just relying on the results.
  • 0
Spoiler

#3 tommah

tommah

    GMC Member

  • GMC Member
  • 275 posts
  • Version:GM:Studio

Posted 25 January 2016 - 03:13 AM

so basically just debugging? I've kind of done that and basically there's no change from what the "slave_dummy" has in its Create Event.  Though as I'm typing this I guess I haven't tried monitoring the Send data, only the receive data so I'll give that a shot and update.

 

*Edit*

I tried debugging a little more by creating debugger=-1 then changed it to this:

with test_dummy{
    buffer_seek( other.buffer , buffer_seek_start , 0 );
    buffer_write( other.buffer , buffer_u8 , 2 ); //data identity
    buffer_write( other.buffer , buffer_u32 , id );//specific ID
    buffer_write( other.buffer , buffer_u32 , x ); //location
    buffer_write( other.buffer , buffer_u32 , y );
    debugger=sprite_index
    buffer_write( other.buffer , buffer_u32 , sprite_index);
    network_send_packet(other.socket,other.buffer,buffer_tell(other.buffer));  
}

so it sets "debugger" to sprite_index before writing and sending and draws "debugger" string above the sprite.  Then changed the receive to this:

with slave_dummy{
            if index=other.NetIndex{
                x=buffer_read(other.buffer,buffer_u32);
                y=buffer_read(other.buffer,buffer_u32);
                debugger=buffer_read(other.buffer,buffer_u32);
                other.Enemyfind=1
            }
        }

Same thing, should set "debugger" to the incoming sprite_index, then draw the incoming "sprite_index" above sprite.  However as before there is no change on the Client side.  Host NPCs show their sprite_index string (generally number around 480), Client NPCs show -1 no matter what.  x and y is perfect, they are completely synced up for as long as I test it but its like the Client doesn't read anything afterwards.


Edited by tommah, 25 January 2016 - 01:36 PM.

  • 0

#4 tommah

tommah

    GMC Member

  • GMC Member
  • 275 posts
  • Version:GM:Studio

Posted 26 January 2016 - 02:49 PM   Best Answer

So I changed all the buffer types from "buffer_u32" to "buffer_u16" and it seems to be working mostly like it should, although the NPCs on the client side are blinking and the fps nosedive is still there.

 

*Edit*

Fixed it:

        var Enemyfind=-1;
        var InsNo=instance_number(slave_dummy);
        var NetIndex=buffer_read(buffer,buffer_u16);
        for(i=0;i<InsNo;i+=1){ //this was the difference
            var Ins=instance_find(slave_dummy,i);
            if Ins.index=NetIndex{
                Ins.x=buffer_read(buffer,buffer_u16);
                Ins.y=buffer_read(buffer,buffer_u16);
                Ins.sprite_index=buffer_read(buffer,buffer_u16);
                Ins.image_index=buffer_read(buffer,buffer_u16);
                Ins.isalive=buffer_read(buffer,buffer_u16);
                Enemyfind=1
            }
            if Enemyfind=1 break;
        }
        if Enemyfind=-1{
            var xx=buffer_read(buffer,buffer_u16);
            var yy=buffer_read(buffer,buffer_u16);
            var spr=buffer_read(buffer,buffer_u16);
            SlaveNPC=instance_create(xx,yy,slave_dummy);
            SlaveNPC.sprite_index=spr
            SlaveNPC.index=NetIndex;
            SlaveNPC.NetKill=false;
        }

After getting the sprite_index to work by changing to buffer type to "buffer_u16", I wrote this for loops instead of using "with".  Fixed all problems, even the FPS drop issue.


Edited by tommah, 26 January 2016 - 05:05 PM.

  • 1

#5 Xer0botXer0

Xer0botXer0

    GMC Member

  • GMC Member
  • 770 posts
  • Version:GM:Studio

Posted 26 March 2016 - 05:34 AM

ha Tommah! Solved my problem thanks for making this thread!


  • 0

//=====================

Good bye, Farewell GMC! :D

See you all in the next TIER!

======================\\


#6 tommah

tommah

    GMC Member

  • GMC Member
  • 275 posts
  • Version:GM:Studio

Posted 26 March 2016 - 01:07 PM

No prob
  • 0





Also tagged with one or more of these keywords: gm:studio