Associate player object to peer with room management and post-connection switching map

0 favourites
  • 13 posts
From the Asset Store
Two types of minimap: "full map" and "player is the center" (square map and radial map)
  • Hello folks,

    I have the exact same (or very similar) issue as this person construct.net/en/forum/construct-2/how-do-i-18/multiplayer-peer-problem-112589.

    To go straight to the point, my peer join the room before the map and the player sprite is created. Here is the workflow :

    1. The host create a room
    2. A peer join the room
    3. The host pick the mission to start
    4. The host is teleported to the game map
    5. The host broadcast a message "loadMap"
    6. Every peer load the map and send a mapIsLoaded message to the host
    7. The host create at that point the player game object for the peer
    8. Every peer need to set the correct peerId and associate it with the created game object

    The issue is at the last step, the peer sometimes does not get the correct peerId and get host one. Indeed, depending on how things going on, the "Multiplayer.PeerID" can be the correct value or not.

    I have tried lot of things described in the linked post, and I have seriously no idea about what to try next. I thought that the object Uid could be the same, but unfortunately it is not the case. I have tried to sync the peerId value, but it's not working as well.

    Do you have any ideas/suggestions to solve this issue ?

    Thanks a lot for your help

    Tagged:

  • Without analyzing or testing this too closely, I think the problem you're having is that the Multiplayer.PeerID expression is supposed to work specifically in certain triggered conditions, like OnPeerConnected. When you use it like that outside the trigger, you won't get the right PeerID.

    An approach I would try (but have not tested), would be to store the relevant peerIDs of each player in an array upon joining, and use that array to look up and assign/associate peerIDs to objects for each player when you want to create player objects.

  • there are a lot of problems in this screenshot

    not is host is only relevant while in a room, not while connected to the signalling server

    players on created really doesn'T mean anything. IT should be, on peer connected, create object players, set peer ID, associate, and everything else right after a on peer connected to room

  • Without analyzing or testing this too closely, I think the problem you're having is that the Multiplayer.PeerID expression is supposed to work specifically in certain triggered conditions, like OnPeerConnected. When you use it like that outside the trigger, you won't get the right PeerID.

    Thanks oosyrag for your thought, I agree mainly that Multiplayer.PeerId have inconsistent behaviour when used outside the OnPeerConnected trigger. Sadly, it seems that OnPeerMessage does not "attached" the context to the created object - not sure if it can be considered as a bug or it's as designed.

    An approach I would try (but have not tested), would be to store the relevant peerIDs of each player in an array upon joining, and use that array to look up and assign/associate peerIDs to objects for each player when you want to create player objects.

    I have tried to build a JSON object of players with their aliases/objectUid/peerId. The issue is that the objectUid is the one from the host and unfortunately, game object have different objectUid on peer side which prevent me to associate the peerId to corresponding game object. When a player game object is created, only the X/Y/LAYER data are sync until the object is synchronised with the Associate method and none of this is enough to identify a user, except a dirty workaround based on X/Y coordinate but I am really scared about the side effect and prefer to not go on this way...

    Hey eleanorjmorel,

    While I totally agree with your message, you may need some context to better understand why I have for instance "connected to the signalling server". It's a "cheap" way to distinguish OFFLINE from ONLINE behavior on my event sheet. I could have used "Is inside a room" but anyway, I don't think the issue is linked to that specific things.

    As described in my post, I can't use the "on peer connected" event since the peer is already connected for a while. In many game, you don't directly jump to the game screen, you may stay in a waiting room layout until everybody is ready and then be moved from the room layout to the actual game layout. That's the reason why I have used message to inform peer to load a map, and to inform host that the peer has successfully loaded the map.

    I could attached a game sample to illustrate the issue but it require me to clean all my assets before. Moreover, the game sample will still have lot of code and may be complicated to debug without spending (lot of) times... not sure to get lot of answers anyway.

  • you can also use this instead of using the sync action for more flexibility drive.google.com/file/d/1FmEtzZJt_18EVaAoL5sBFS6h69xCr1OD/view

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you can also use this instead of using the sync action for more flexibility drive.google.com/file/d/1FmEtzZJt_18EVaAoL5sBFS6h69xCr1OD/view

    Thanks eleanorjmorel, that require lot of rework I suppose and I seriously doubt that the code will remains clear :-D. I could send player data periodically but is a bit sad to go back to code when you have a tool like Construct. I am thinking also at some other cheap workaround, such as moving everybody to an another room when map is loaded. Then I could end up using "on peer connected". If only if Multiplayer.PeerId could be correctly set when the root event come from On Peer Message, that would be awesome.

  • It's not a bug.

    You also don't need object uid or alias or anything.

    If you have a list of peerids, then you simply create a object for each of them. Set the instance variable to each peer id in order, and sync it.

  • It's not a bug.

    You also don't need object uid or alias or anything.

    If you have a list of peerids, then you simply create a object for each of them. Set the instance variable to each peer id in order, and sync it.

    Hey oosyrag,

    Regarding the bug status, I am not that sure but that's my own opinion. OnPeerConnected or OnPeerMessage from my point of view should set the peerId to the context, so no matter you create a character in both of this event, you should have the right and proper peerId.

    For instance, on the multiplayer sample from Construct's team (hope that attaching multiple screen will works...) :

    So why it's not the case when I have this on my side ?

    The only difference is that PeerId seems not correctly "transmitted" to the CharacterCreation in case we receive a peerMessage. And what is so strange, is that my code sometimes works, sometimes don't. It's not clear when exactly peerId is set which is not convenient, maybe you can tell me more about that.

    Regarding your suggestions, unfotunately, is it not possible. On host side, everything is fine. Peer/host seems associated.

    The issue is located on peer side. As soon as the character is created on server side, since it's "sync", it is also created on peer side. However, seems that this is the only things that happen, any variable on character is not sync on the peer side. In order to be sync, the peer side need to associate the newly created character object to a peerId, which cannot be found in any way.

  • My mistake, I forgot strings like peerID cannot be synced through the sync instance variable action. I'll revisit this shortly.

  • I have spent few hours to recreate a game and fortunately (or not) I can't reproduce this specific issue.

    However I encountered an issue that could (or not) be linked and that I can reproduce also in my game.

    If both the host and the peer connect to the game, everything is fine.

    If the host connect to the game, start the map, and then a peer launch the game, connect it, seems it can't move his character.

    Here is my project sample easyupload.io/eak5u4

    The steps to reproduce the issue :

    1. Open the project and remote preview it
    2. On a browser, go to the remote debug and clic on the Start game button
    3. When the host is connected to the game and can move the red square (this is very important to wait the host is on the game before doing the following), open a private browser and go to the game again to simulate a peer
    4. Click on Declare as ready button for the peer, you should be moved to the game map
    5. Host can move freely and are sync with peer, but peer cannot move
  • Here is the issue from the OP (I haven't looked at your last post yet). Since we can't sync strings in instance variables, we send a message instead. This is also better because the PID doesn't actually need to be synced, since it shouldn't be changing after being initially set anyway.

    However, if the host creates an object and sends the message with the peerID associated with it, we won't be able to know if the sync feature will create that object on peer clients first, or if the message will arrive first.

    When the message arrives, it will check if the last created object has a PID already. If it does, store the PID in a variable, for use when the new object is created. Otherwise, set the PID in the last created object has an empty PID.

    Similarly, when an object is created (from syncing with the host), check if there is a PID in the variable, and use that and clear the variable if there is. Otherwise, do nothing, and wait for the message to arrive to assign the PID.

    Edit: link removed, bad example

  • Revisited this recently and wanted to post an updated example before my subscription expires. Apparently multiplayer.peerid does get updated correctly within an 'on created' trigger on the peer side if the object is created via syncing from the host within an 'on peer message received' event. So there is no need to manually send a message with the peerID string and try to buffer it like I did in my previous example, which was unnecessarily complicated. Here is a minimal example where peers can send a message to spawn an object instead of in the 'on peer connected' trigger, and the PeerIDs are still properly communicated.

    dropbox.com/s/p3vwhjlfs7xlxmx/MP_LateJoin_CharacterSelect_Example.c3p

    It seems like this is the approach that the OP originally tried and had issues with, but it worked fine for me so I'm still unfortunately still not sure what the problem was as he couldn't recreate it either.

  • Hello oosyrag,

    Thanks for your message. I have since decided to give up on this project because of this issue.

    I will maybe one day go back to this project, and anyway will "soon" add online to my current offline game, just hope to be better prepared to face this kind of issue...

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