How do I sync global variables over Multiplayer?

0 favourites
  • 12 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I am trying to sync a global variable in multiplayer where when the global variable changes from the host, it shows this to every other peer. Any help is grateful.

  • If they all numbers you could simply sync them as part of a synced object. Otherwise you can broadcast peer messages whenever they are changed. Just make the message ID the global var name and the message the value.

    Attached a screenshot showing this in action.

  • mzo I tried that but get NaN as the value... do you know what that means?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm I am trying to set the variable over two different layouts... could this be the problem?

    For example, Player 1 (the host) sets his player card value as 6. Next, Player 1 card value then is stored in a global variable, Player1Card. He then broadcast the message over to his peers (which are all on different layouts). The peers do not receive the value but a NaN value instead. (I did some research on what NaN stands for and it stands for Not A Number) SO the peers are not receiving a number value. I'm thinking maybe because they are on different layouts that the action is not being signaled to the rest of the peers. Also using the broadcast message action needs a string, no?

  • Here's some screenshots of what I am doing. I hope it helps.



  • The broadcast message is broadcasted as a string (Not a Number ). Try assigning it with int(Multiplayer.message).

  • Tried that and it still doesn't work. It gives me a value of 0. :/

  • Can you attach a CapX?

  • I don't what I did but now it is working. Maybe it is because I used the sync variable and now it works for the peers. They are receiving the value now. But I've come to another problem, before it was the host having the problem sending the card value, now, it's the peer that cannot send its value to the host. Any idea on how to update the host with the peer values? I've been reading the multiplayer tutorials over and over, and they are a big help, just kind of hard to grasp the process in your first complex multiplayer game I guess. Just when I think I got it, something else comes up. Thanks for trying to help me. It is very much appreciated.

  • This thread is solved. I found out my the solution from the entry here. What was wrong on my part was that I had conflicting actions in each layout, so it couldn't sync the global variable correctly.

  • When it comes to using Sync variables, its one directional only, host->clients.

    There's two ways that data comes from the clients:

    • Inputs (see the multiplayer tutorials)
    • Messages
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)