How do I sync ids for objects not associated with a peer?

Get help using Construct 2

Post » Wed May 20, 2015 7:22 pm

Here is my problem abstracted from my game and put as simply as I can make it:

There is a multiplayer game where the player controls an object named hero.
Hero is sync'd via the multiplayer object and has an instance variable named peerid.
Whenever hero collides with a certain object, an object named follower is created.
Follower is also sync'd via the multiplayer object and has an instance variable named peerid.
Follower.peerid is set to hero.peerid on follower's creation.
Occasionally hero triggers an event that changes his opacity to 50.
The design of the game calls for follower to mimic all visual effects of it's hero.

For the host this is as simple as a condition:
->hero on collision with object (this is the trigger)
-follower.peerid = hero.peerid (this is the added condition)

The host has now selected all objects that he wish to change visually.
The problem occurs when trying to mimic the visual change for peers.

Lets say after the host changes the opacity of the selected hero and followers he broadcast a message to all peers.
The tag is "setOpactity50" and the message is hero.peerid.

The peer has an event for that tag ("setOpacity50") that selects a hero object using the message (peer.id) and changes it's opacity to 50.
Unfortunately the peer has no way of determining which followers to select and therefore cannot mimic the visual change.

For the peer, when hero is created by the multiplayer object we can set its peerid to multiplayer.peerid.**
However, when follower is created we cannot set it's peerid using the same method.
I can't sync the variable because peerid's are strings.
I can't use peer messages on follower creation because the peer will still not be able to pick out which follower to assign the id I pass to.

Current workaround:
I made a copy of my project and i'm slowing going through and redoing every section using a new id system that consist of only numbers.
This way I can sync the variable. However, this seems silly so I thought I'd come here asking for help.

Other notes:
I know this is a long post but it's a complicated problem and I've done my best to make it as simple as possible.
Thank you for taking the time to read this and feel free to ask for clarifications if the problem is not clear.


**To be honest I don't understand how this is possible since the host associates the object with a peer after creating it so how would it be able to send a peer id before it knew what it was. Unless when we create an object, object on created doesn't trigger until after the events following create object. Either way this isn't too important but may be fundamental to something I'm miss understanding in the order of events.
B
5
S
1
Posts: 9
Reputation: 345

Post » Wed May 20, 2015 8:31 pm

Hero spawn follower
set follower.peerid = hero.peerid ;)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu May 21, 2015 2:58 pm

That would work but all followers are spawned by the multiplayer object via sync object.
B
5
S
1
Posts: 9
Reputation: 345

Post » Thu May 21, 2015 5:04 pm

Host broadcasts message with the peer ID set by the host and its X,Y coordinates.

Peers receives message, and picks the nearest follower to position X,Y form the message and sets the peerid required.

That would also solve other peers in game setting the correct ID as well
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, valefor and 23 guests