How do I send a client state from the host's variables to the client?

  • Hi guys, I know this sounds strange, but my project requires it and I can't figure out how it works!

    In my game, the host is handling all character movement and the peers only get character stats. The multiplayer connection is working just fine and I'm able to send messages from the peer to the host.

    However, I'd like to be able to sync the host's "peer-avatar-object"'s variables with the peer's avatar variables.

    All multiplayer tutorials that I found always consider the peer as an "emitter" that synchs with the host.

    I want it to be able to sync object variables just as if it was the host receiving them from the peers.

    I could use messages from the host to the peer, but as I understood, it isn't as effective nor practical for constant flows of info.

    In other words:

    My host handles a "Health" variable for each avatar. I would like to have the peers know what their "Health" is as frequently as possible.

    Tutorials only show how to send peer info to the host and let it update automatically via synch.

    How can I accomplish this?

    Thanks!

    -ViLa

  • This is the current code for my peer side (which doesnt work):

    i.gyazo.com/c0ee6262b6f26ef03ff65cc93c1e1beb.png

    This is the host side:

    i.gyazo.com/fcfcd4d6bc24fbb8aec9363496b89b42.png

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • why not only send health information when it changes

  • why not only send health information when it changes

    Hey thank you for your reply!

    Well, it is supposed to be a set of stats that change all the time... and I read Ashley say somewhere that for that kind of thing its more reasonable to sync object variables - which I can't figure out how it works.

  • Peer:

    ok so it's pretty wrong, you only need to do "sync" once so that the multiplayer plugin knows what objects to sync, and then every single one of those objects will by sync'd it's not a per object thing.

    avatar.on_created should set the ID to multiplayer.peerID because it'S the host that creates and deletes objects that are synced

    an object that is synced that has an "on created" event will have multiplayer stuff hidden in it it's like never explained but thatS' how it works

    Host:

    you create an object but no peers are picked so associating the object with multiplayer.peerID won'T do anything.

    again sync only need to be done once. sync and input values.

    You're missing the event where you do the sync of tags of input states for each players to set the instances variables on the host'S side

  • Wow thank you so much for your reply!

    Such a trove of information. I will look into it and see if I manage to figure it out.

    I'll look into it!

    Thank you so much YoyoEleanor - you've been helping me out a lot lately! :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)