How do I sync global variables over Multiplayer?

Get help using Construct 2

Post » Fri Apr 18, 2014 12:02 am

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.
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Fri Apr 18, 2014 2:09 am

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.
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 17
Reputation: 1,484

Post » Fri Apr 18, 2014 5:11 am

@mzo I tried that but get NaN as the value... do you know what that means?
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Fri Apr 18, 2014 6:34 pm

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?
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Sat Apr 19, 2014 3:24 am

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

action.png


global variable.png
You do not have the required permissions to view the files attached to this post.
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Sun Apr 20, 2014 11:49 am

The broadcast message is broadcasted as a string (Not a Number ;)). Try assigning it with int(Multiplayer.message).
B
8
S
2
Posts: 17
Reputation: 1,484

Post » Sun Apr 20, 2014 7:14 pm

Tried that and it still doesn't work. It gives me a value of 0. :/
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Mon Apr 21, 2014 10:26 am

Can you attach a CapX?
B
8
S
2
Posts: 17
Reputation: 1,484


Post » Tue Apr 22, 2014 4:48 pm

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.
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests