How do I Sync multiple objects between 2 or more players

Get help using Construct 2

Post » Wed May 10, 2017 8:38 pm

Hi all

I'm working on a "simple" RTS, using the default multiplayer plugin. Thus far, I have my lobby / room all setup and it works just fine. Furthermore, I'm switching layouts for maps, while the host / peers remain connected. This too works fine. However, I'm having some issues with sync. object.

Setup
In my setup, I'm doing the following:

1. I sync. a Family called Units (position and angle)

Code: Select all
Multiplayer -> Sync. Units (Family) with Position and angle, precision Low (int16, 2 bytes) at Normal bandwidth


2. When a unit is created, it is associated with Multiplayer.PeerId for both the Host and the Peer side.

Code: Select all
Units (Family) on created:
                   Units (Family) -> Set peerId to Multiplayer.PeerID
                   Multiplayer -> Associate Units (Family) with Multiplayer.PeerID


Creating Units

1. The host is creating a single unit per peer, on layout start

Code: Select all
System for each Player (Sprite that represents peer)
                  Create object "Worker" (Part of Units Family) on layer "units" at (posX, posY)
                  "Worker" set peerId to Player.peerId


2. The host is responsible for some path finding / moving

Code: Select all
N/A - Not important in this context.


This all works well enough - just a very small delay in unit movement, on the peer side.

Problem Creating Multiple Units

1. The host creates two (or more) units per peer, on layout start

Code: Select all
function createWorker(peerId, posX, posY)
                  Create object "Worker" (Part of Units Family) on layer "units" at (posX, posY)
                  "Worker" set peerId to peerId

System for each Player (Sprite that represents peer)
                  call "createWorker" (Player.peerId, 100, 100)
                  call "createWorker" (Player.peerId, 150, 100)
                  ...etc


While the host appears to have everything in order, all peers mess this completely up. The units are created on the host and the peers. Yet they are not associated with themselves on the peer side. The peers gain control (association) with at most a single unit, which was assigned to them.

Does anyone have an idea why?
Must I really sync. the native object, instead of a family in my setup... Or must I invoke sync. object per created instance (seems unlikely)? Should the host wait some given interval before creating unit number 2, 3.. etc, per peer?
B
6
S
1
Posts: 3
Reputation: 306

Post » Thu May 11, 2017 8:29 am

With multiple units of the same family/object you can not associate objects with peerid, that only works if each peer has just one of those objects.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Thu May 11, 2017 3:38 pm

Okay, sure - I guess that makes somewhat sense of the issue that I'm facing. However, how - if at all possible - can I control multiple units of the same type object, per peer?

I mean that, for my game, each player should be able to have multiple "worker", which I somehow must sync their position, state and perhaps a few other properties, e.g. health.
B
6
S
1
Posts: 3
Reputation: 306

Post » Thu May 11, 2017 4:14 pm

aedart wrote:Okay, sure - I guess that makes somewhat sense of the issue that I'm facing. However, how - if at all possible - can I control multiple units of the same type object, per peer?

I mean that, for my game, each player should be able to have multiple "worker", which I somehow must sync their position, state and perhaps a few other properties, e.g. health.




Yes that definitely works, I have a template in the arcade with downloadable capx

https://www.scirra.com/arcade/multiplay ... -746?cp=12
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Fri May 12, 2017 6:11 pm

Aha, I see. Thanks mate - your template is a very good inspiration for what I wish to achieve.
B
6
S
1
Posts: 3
Reputation: 306


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, KTML5, XavierOrionGames and 5 guests