How do I Sync arrays Over Multiplayer?

0 favourites
  • 12 posts
From the Asset Store
Sync animations, animation frames, mirror state, sounds and anything else using these methods.
  • 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.

  • 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.

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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!

  • Ashley I tried doing it like this, but it still isn't working. Am I getting close?

  • 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.

  • Ashley I am not sending it every tick. I finally got it working now. Thank you so much for your help!

  • 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!

  • 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

  • There is no 'solved' option, I don't see much point in it either (it might discourage someone from checking the thread and posting a better solution).

    It would however be useful to post what you did wrong and what you did to fix it, so others who find the thread in future can learn from it.

  • I figured out what I was doing wrong, I was not loading the peer message as Multiplayer.Message but using the array_name.AsJSON instead.

    If anyone needs help with sending an array over multiplayer, this is how you do it:

    1. First to make the Host broadcast the message.

    Make sure you put this in the Host group.

    Use the Host "Broadcast Message" (in multiplayer feature).

    In the "tag" slot you could use whatever tag you please and in the "message" slot you should use

    (the array name you are trying to send).AsJSON

    So it should look something like this array_name.AsJSON in the message.

    2. Now to make the peer receive the message.

    Make sure you put this in the Peer group.

    Using the multiplayer feature, click on "On peer message",

    when you do, it will ask for a tag. Use the same tag you used with the Host.

    Next, you click on the array you would like to sync up and click on "Load".

    This will bring up the JSON slot and in this slot input Multiplayer.Messge .

    Now it should sync up. That is all there is to it. Hope this helps! Thanks Ashley for the help, could not have done it without you.

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