How do I Sync arrays Over Multiplayer?

Get help using Construct 2

Post » Fri Apr 11, 2014 11:44 pm

I am trying to make a multiplayer card game using construct 2 and I came into a roadblock in the development. I was wondering if anyone knows how to sync arrays using the multiplayer feature. For example, the host shuffles the cards and put the result into an array. How do I update the values of that array to the rest of the peers. Any information would be grateful.
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Sat Apr 12, 2014 2:31 pm

Support is not built in, but it should be easy to achieve using normal messages. If the array is small, you can just send it as JSON text (using the AsJSON expression). If it's large then that method will waste bandwidth, so you could instead have a message that is sent when individual indices change.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Sun Apr 13, 2014 6:00 pm

Ashley wrote:Support is not built in, but it should be easy to achieve using normal messages. If the array is small, you can just send it as JSON text (using the AsJSON expression). If it's large then that method will waste bandwidth, so you could instead have a message that is sent when individual indices change.


Thanks for the reply Ashely. Could you give me a step by step example of the method like how you would do it in construct. Would I use websocket?

1. The host has array.
2.Set as JSON text (using websocket?).
3.Sends to peers.
4.Peers update game with that JSON text?
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Sun Apr 13, 2014 7:44 pm

No, not websockets, just the multiplayer object's 'send message' or 'broadcast message' actions. A bit like chat messages from the chat example but with array data instead of a textbox's text.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Sun Apr 13, 2014 8:50 pm

Ashley wrote:No, not websockets, just the multiplayer object's 'send message' or 'broadcast message' actions. A bit like chat messages from the chat example but with array data instead of a textbox's text.


Oh ok, I guess that makes sense. I have the idea of the process in my head, but I don't know how to execute it yet. I'm going to analyze the multiplayer chat and try to figure out from there. But nonetheless, thanks for the quick reply Ashley. I shall try to fiddle with it more. Cheers!
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Tue Apr 15, 2014 1:56 am

@Ashley I tried doing it like this, but it still isn't working. Am I getting close?
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 » Tue Apr 15, 2014 12:24 pm

It looks about right, but I can't see the rest of your events, and you most certainly should not be sending every tick, which I can't see if you're doing or not.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Wed Apr 16, 2014 1:51 am

@Ashley I am not sending it every tick. I finally got it working now. Thank you so much for your help!
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Wed Apr 16, 2014 2:00 am

Since this is my first fourm, I was wondering how do I make this forum status "solved" ? Or is there no button for that. Thanks guys. Scirra is the best!
B
19
S
3
G
1
Posts: 37
Reputation: 1,433

Post » Wed Apr 16, 2014 11:33 am

Wsoukkachang wrote:Since this is my first fourm, I was wondering how do I make this forum status "solved" ? Or is there no button for that. Thanks guys. Scirra is the best!


Just edit your origanal post (first one) and put [SOLVED] in the title ;)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Next

Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, Mayfly, tarek2 and 14 guests