Help on multiplayer object not syncing (I think??)

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi,

    I'm working on a multiplayer card game, basically a Hearthstone clone, so I can get my head around the general construct to build something more complex later.

    Being completely new to Construct, and game design in general, I built the game with a very simple AI first, and I'm now going back and adding in multiplayer (and realising that was a perhaps not the best idea) but I'm falling down at a very early hurdle.

    I've built a card select screen, which you land on after logging in. on this screen, I need to create a variable amount on instances of my Deck object, which displays the cards, set several variables to each, being pulled from an array based on the animation frame of each card, and arrange them on the screen to be selected (there is more to do after that, but it's this early I'm falling down.

    The host creates the objects by looping through the array with the stats and creating an object for each entry, I then have a series of actions set to run on every tick that rearranges the cards based on a formula using the loopindex and ordering by animation frame. This all works perfectly on the host machine, but I am not getting the right result on the peer.

    I have it set up as such:

    On start of layout > sync Deck and necessary variables

    Signalling server login stuff

    On Signalling joined room > AJAX: request Cards.json

    On "Cards" Complete > array: load from ajax.last data

    create cards, etc

    I know everything up to here is working as it is working on the host. Then:

    On peer connect > function to broadcast message with cards array as .json

    On message received > array:load from message & send message back that array has loaded

    On message received > broadcast message back to peer

    On message received > events to assign animation frame to cards on peer machine

    It seems to be on this last step that it falls down. I've added some bits of text to try to help me debug and I've discovered a few things that are puzzling to me. Firstly, on the peer machine the count of instances of the cards shows 1 more than on the host (I didn't think that could happen with the object synced?), next, as part of the reaction to the last message the peer receives, I added a for each loop on the card object and told it to append a text field with what should be the animation frame (stored as a variable, synced from the host) of each card, and despite my count saying there were 22 instances, the loop only returned two figures?

    I am very confused??

    Here's my files (although apologies in advance for the mess, as I said I'm learning as I go, and trying to retro fit multiplayer to something I'd already built)

    Everything I've described above is on event sheets PS-DeckBuilder, PS-Outgoing, & PS-Incoming

    https://drive.google.com/open?id=1N3aNkzdxVEp8sbw3bFCHMjrgDQ_Gkyof

  • OK, so I've gone back and tried this another way, by not syncing the object for the cards, and instead creating and destroying them independently on the host and client side. This was how I originally thought to do it, but after doing some reading, I got concerned that all objects should be being created by the host. Then I realised that this only applies if you're using sync object (at least I think that's right) so this is presumably the better way to do it, it you want the players to control the setup of the cards on screen individually? Please correct me if not.

    Anyway, having gone back to doing it without sync, I am instead using arrays to store some information about which cards are where, and sending instance variables back and forth with messages for the rest of the information about the cards. I've managed to get the card select working, but I'm now running into some issues when loading into the main layout for the game. It seems to be an issue around the timing of certain messages being sent from host to client and back again, as the outcome varies depending on if the host or client sends a ready message first.

    If the host readies first, the game loads and both players are dealt a 4 card hand, as is supposed to happen, but if it is then the hosts turn first the host is dealt 2 extra cards, instead of one as it is supposed to, and and receives and extra thruster (a global variable which is basically my version of mana from hearthstone, etc) the same even triggers both actions and is set to trigger once if global variable PlayerTurn=0

    If the client readies first, the game starts, but they receive no starting hand, however, the host doesn't receive an extra card and thruster.

    Here's my latest project file, I've started a new event sheet for the main layout, keeping the old one for the functions I'd already created on it, so everything relating to my issues is on the sheets PS-MainNew, PS-Functions, PS-Outgoing and PS-Incoming.

    https://drive.google.com/open?id=1pPICKz9-akfGD2UbfKyEIJHTegAHEjei

    If anyone's able to point me in the right direction, I'd be very grateful. Every time I think I'm getting my head around multiplayer, it throws another curve ball at me!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK, actually, I've just run it again, and the client seems to now always be receiving their starting hand, but the host is definitely only receiving the extra card and thruster when the client readies first, but I really can't see why this would be???

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