How do I Access a Peer's global variables

Get help using Construct 2

Post » Mon Mar 21, 2016 7:30 pm

In my multiplayer game I want players to be able to pick their characters so in the beginning they pick one and it's stored as a number in a global variable, how can I have the host access it?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Mon Mar 21, 2016 10:21 pm

https://www.scirra.com/manual/174/multiplayer

Send message
Send a message to a specific peer with a given reliability mode. Peers can only message the host (and the Peer ID field must be left empty), but the host can send a message to any peer. Message tags can be used to identify messages for different purposes, such as "chat" or "gameplay-event". The message must be a text string, but could also be JSON data such as from an Array or Dictionary AsJSON expression; however be sure to avoid wasting bandwidth. The order messages arrive, or whether it is guaranteed to arrive at all, depends on the reliability mode.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Mar 22, 2016 2:42 am

I tried on signaling room joined, send a message to the host with a number for it's tag depending on the character picked and when the host receives a one of those numbers to spawn a corresponding character but that didn't work. How should I code it?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Mar 22, 2016 8:02 am

The tag isn't meant for sending the data, just for identifying the type of message. You should put data you plan to use in the message itself. If it is a number, use int() to convert it back to a number from the data string after you send it.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Mar 22, 2016 6:38 pm

Ok, I have that when you're not the host send a message to the host with the value for the player you picked before.
For the host it says that when it gets that message to set the global value character to int(multiplayer.message) and then it checks what the global variable is to spawn a character but that doesn't seem to work either
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Mar 22, 2016 8:43 pm

I won't be able to diagnose much further without seeing the debug.

Can you check if the host is receiving the message and setting the variable on the host to the correct value? Also confirm that the host is able to spawn a character on its own properly based on a static variable.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Mar 22, 2016 9:39 pm

Ok I'll check that stuff out and if it still doesn't work I'll post a capx
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Mar 22, 2016 10:00 pm

The issue seems to be that if I try to use on peer connected as a trigger the message doesn't send
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Mar 22, 2016 10:18 pm

I think on peer connected, as the peer, will not trigger. It seems like on peer connected is for the host to know when a peer connects. For the peer, I think you want to use On Joined Room.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Mar 22, 2016 10:33 pm

Hmm that doesn't seem to work either but I figured a way around it :)
B
22
S
8
Posts: 203
Reputation: 2,059


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 9 guests