How do I sync host and peer in a multiplayer turn based game?

0 favourites
  • 7 posts
From the Asset Store
Sync animations, animation frames, mirror state, sounds and anything else using these methods.
  • Hi all,

    I released my game “Cornhole Duels” few days ago, that is a turn-based game, with the possibility to play only on local computer in different modes:

    - versus cpu

    - versus player

    - training

    The game is simple, when global variable Turn is “Player 1” then you can use arrows up and down to aim and then press spacebar to shoot. The same controls when turn variable becomes “Player 2”.

    Both players have same simple controls.

    Now I’m trying to implement online multiplayer and I was able (following tutorials) to arrive at the point where peer joins the host’s room.

    I can’t understand how then to make everything working with syncs.

    I created Host, Peer and Common group.

    Do I have to put my “game core functions” under Host group?

    Do have I to create single instance variables of objects in the game layout and then update these and send messages to peer with updated ones?

    Do I just need to sync objects?

    Have tried with messages but just achieved how to see same texts for host and peer.

    If anybody could help me I appreciate.

    Just let me know and I’ll share with you the capx of the multiplayer version, if needed to better help me out.

    Thanks and regards

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should do read and follow the multiplayer tutorials.

    You can consider the host to be the "real" game. Syncing refers to updating synced objects' properties (position, angle) on peers to match the host's game state.

    Peers send their inputs to the host via input states or messages, and the host then applies those inputs to the game objects, which are then synced back to peers.

    In a real time game, to hide latency, peers can also apply their inputs to their local copies immediately when pressed by using local input prediction.

    Syncing objects and local input prediction are sometimes not necessary in a turn based game, given that results of inputs are deterministic. That is when the result of any particular input will always be the same on any device. Messages can work fine in this case for peers to communicate with the host either what was input, or the result of what happened after the input (or both). If not using synced objects, the host will then need to forward the same message to all the other peers. Naturally that doesn't apply if there are only 2 players involved.

  • I read and did the tutorials but I can’t put what I did in my game.

    The “core functions” of my game should be under host group?

    Or should they be by theirselves?

  • Anything you want handled by the host, should be in the host group. This would normally be most of the game.

  • Thanks mate, I was able to sync part of the game between host and peer.

    What I don’t understand is how to sync inputs.

    I better explain: normally in the game that is one vs one on the same screen (turn based game) there is a global variable Turn. When Turn = Player1 then the controls perform actions (chose throw angle with up and down arrows and throw power keeping pressed space as much as you want) only for player 1. The same for player 2 when the variable is Player2.

    If I create an invisible item with an instance variable turn and when global variable is Player 1, this instance variable must be the same (also for P2) and then I send a message from host to share that this item with instance variable has been updated, then what do I need to do to let only P2 (peer) using controls and share results with host?

    Thanks a lot for the help.

  • The peer will need to let the host know that it wants to do something, either by sending a message with the result, or sending it's input states, and the host can decide what to do about it.

    For example by input state I mean for example if the peer clicked a button on their screen, the peer would sync/send the input states of clicked, and the coordinates where it was clicked. The host would determine what to do/update, based on what it expects to be at those coordinates.

    By message, it would mean for the peer, on clicked button, would send a message to the host saying " I clicked this button" or equivalent, and the host would determine what to do on message received, for that particular message.

  • Hi mate!

    I was finally able to do some changes.

    As you can see from the c3p attached file, I can sync some objects between Host and Peer.

    I can't perform sync of inputs. When is P2 turn, from Peer game I'm not able to let P2 use its controls.

    Please, could you help me?

    drive.google.com/file/d/1MOb8pofH_3iPCxiTsTk8qj92V9DvDIk6/view

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