Syncing Variables & Mouse Clicks Multiplayer

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hey,

    Super new here, I am hoping someone can point me in the right direction. I have a little test file where I have been trying to learn different concepts. I am finding it pretty simple to create things, however I've just moved onto Multiplayer and this is a whole new beast.

    I am wondering if anyone could give a little advice on syncing variables for the trees in my capx. I have tried to get this working solely for the host at the minute however this does not get destroyed on the client side. I'm probably doing something really obvious wrong.

    I would also like to receive inputs from the peers mouse clicks on multiplayer. What would be the best way to do this. I'm struggling to find any information on this. Ideally they would hit a tree and this variable would be synced.

    Sorry for the mess of a file, as I say it's just a test file to proof different concepts.

    https://drive.google.com/file/d/17KBfgJxkNUInJlkB22_DgMciZ0wd40R6/view?usp=sharing

    Many thanks in advance. I've spent a fair while searching before I came here, perhaps I'm just using the wrong search terms.

    <3

    SC

  • Hey

    Here is how to send and receive mouse click inputs. When a peer clicks, use Multiplayer: Send Message. The peer should send a message to the host with the coordinates of the click as the message

    I recommend doing it like this: Click.X & “,” & Click.Y

    Then, on the Host’s end, you can use tokenat() to parse the message.

    If you have any questions about this let me know!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey Noahboy,

    Awesome, I'll give this a try and update. Thanks for the push in the right direction!

    SC

  • Syncing variables (and objects) happens only one way, from host to peer.

    Synced variables can only be number variables, not strings or booleans.

    To communicate with strings, use messages.

    You can send mouse inputs as strings through messages, like how noahboy described. Or you can send mouse inputs as numbers, as described in the multiplayer tutorial part 4. This has the advantage of being lighter in bandwidth and can take advantage of the built in interpolation feature.

    The normal flow of peer to peer multiplayer communication is as follows: A peer sends it's inputs to the host. The host processes these inputs, makes changes, and syncs the changes back to all the peers.

    In the meantime, to hide latency, the peer who sent the input will show the change on their own screen immediately, before getting what actually happened from the host. This is called local input prediction. After the true state of everything arrives from the host, differences are corrected.

    These are all concepts covered in the multiplayer tutorials. If you don't have a decent grasp understanding everything that is done in the tutorials, making a multiplayer game will be exceedingly difficult. So do go through all the tutorials, even if you're not making a real time multiplayer top down shooter.

    For example, given that you want a host authoritative design, a peer would never try to tell the host "I chopped this tree down". The peer only says "I clicked here", and the host would reply "You clicked on a tree, this is the tree's new life", and sync the fact that happened to all the peers.

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