How do I create a player object for each peer connected?

0 favourites
  • 9 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hey!

    I'm creating a lobby for the Construct 3 Multiplayer real-time game.

    But here is the catch: when the game is lauched from the lobby and I switch to the "Game" layout, the condition "on peer connected" doesn't work. Because the host and the peers are already connected to the room.

    So this line doesn't work:

    I thought I could make a condition like "for each peer connected" but it doesn't exist.

    Would you know how to make it work?

    Thanks in advance!

  • I'm not sure I fully understand the question, but first thing that comes to mind is,

    when going to the game layout, just loop through the peers using a for loop

    + System: For "" from 0 to Multiplayer.PeerCount-1

    -> Text: Set text to Multiplayer.PeerIDAt(LoopIndex)

    but instead of setting some text create your player sprite and setting the peerid variable with Multiplayer.PeerIDAt(LoopIndex)

    but maybe I don't understand your question correctly

  • bartalluyn I think you do:)

    It's in other words as the peers are already connected I don't know which conditon I can use to create the players.

    So you think the peercount would work in the same way?

  • What about creating the player sprites on start of layout of the game layout, using the loop I mentioned...

  • It makes sense. So I tried what you said but it doesn't spawn a player for the peers. Though the host can play his player without any difficulties.

    This is what I changed for the host instead of "on peer connected"

    And I left this as before

    If I choose not too use the "on start of layout" condition it produces an infinite amount of players but doesn't seem to associate it to a peer, because the peers can't still control them.

  • Could it be that you need to set the peerId to Multiplayer.PeerIDAt(LoopIndex), and not every player to the same peerId as you do now?

  • It makes sense. So I changed it in the host part with Multiplayer.PeerIDAt(LoopIndex) instead of peerid. But weirdly enough the problem is the same...

  • And did you get rid of the On PlayerCreated logic?

    I think should just be :

    On start of layout

    For loop (as is = ok)

    - Create object

    - Player set peerid = Multiplayer.PeerIDAt(LoopIndex)

    - associate player with Multiplayer.PeerIDAt(LoopIndex),

    IF Multiplayer.PeerIDAt(LoopIndex) = MyID

    enable local input prediction for player

    and lose the on created logic.

    what does that do?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well it's the same.

    BUT I succeeded to make it work;)

    This by leaving the current room and joining another one. This way I could use "on peer connected" as I did before.

    Thank you for your time and valuable help!

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