Need help with multiplayer setup

  • Hi,

    I've been working on a multiplayer game. I followed the instructions in the pong multiplayer that comes with the scirra sample projects. I was able to establish the connection between Host and Peer, and host is displayed on the Peer side but the Peer is being created at (0,0) instead of the defined area.

    Looks like Peer is not able to sync to Host or the host is not updating the sync values properly. I'm not sure where it went wrong. Can you please check the code and help me with it?

    Please check the gameplay for better understanding -

    Subscribe to Construct videos now

    Thanks in advance. Please let me know if you need any further information.

    [Multiplayer]

    ----+ System: GamePlay = "multi"

    --------[Signalling]

    // On start of layout, connect to the signalling server. We also set up which client input values the peers will be using, and sync the Peer object with its position and additional instance variables for the look position, current inputs and player stats.

    ------------+ System: On start of layout

    -------------> Multiplayer: Add client input value tag "x", precision Low (int16, 2 bytes), interpolation None

    -------------> Multiplayer: Add client input value tag "y", precision Low (int16, 2 bytes), interpolation None

    -------------> Multiplayer: Add client input value tag "points", precision Low (int16, 2 bytes), interpolation None

    -------------> Multiplayer: Add client input value tag "player", precision Low (int16, 2 bytes), interpolation None

    -------------> Multiplayer: Sync Creators (with Position only, precision Low (int16, 2 bytes) at Normal bandwidth (unpredictable))

    -------------> Multiplayer: Sync Creators variable Points (precision Low (int16, 2 bytes), interpolation: None, client value tag: "points")

    -------------> Multiplayer: Sync Creators variable Player (precision Low (int16, 2 bytes), interpolation: None, client value tag: "player")

    -------------> Multiplayer: Connect to signalling server "wss://multiplayer.scirra.com"

    // When connected, request to log in.

    ------------+ Multiplayer: On signalling connected

    -------------> Multiplayer: Log in with alias "Sud"

    -------------> TextCoins: Set text to "Connected to server"

    // When logged in, request to join the room. Use auto-join to assign pairs of players in to separate rooms.

    ------------+ Multiplayer: On signalling logged in

    -------------> Multiplayer: Auto-join from room ROOM_NAME for game GAME_NAME instance INSTANCE_NAME (max peers: 2, lock when full)

    -------------> TextCoins: Set text to "Logged in with alias: " & Multiplayer.MyAlias & " (" & Multiplayer.MyID & ")" & newline & "Joining room..."

    // We joined the room: activate either the Host or the Peer group.

    ------------+ Multiplayer: On signalling joined room

    // As the host, we also adopt the existing paddle object on the left of the layout as our own. We must set its peer ID to our own ID and tell the Multiplayer object it is associated with ourselves.

    ----------------+ Multiplayer: Is host

    -----------------> TextCoins: Set text to "Joined Room as Host"

    -----------------> System: Set group "Host" Activated

    -----------------> Creators: Set peerid to Multiplayer.MyID

    -----------------> Multiplayer: Associate Creators with peer Multiplayer.MyID

    // When not the host, the paddle object already in the layout is destroyed. 'Sync object' will create both paddles, and they'll be associated with the correct player using the 'On created' trigger in the 'Peer' group. Also since the game is 2-player, it can begin as soon as the peer joins since we know the host is already there, so update the game state to "getready".

    ----------------+ System: Else

    -----------------> TextCoins: Set text to "Joined Room as Guest"

    -----------------> System: Set group "Peer" Activated

    -----------------> Creators: Destroy

    -----------------> System: Set GameState to "getready"

    ------------+ Multiplayer: On signalling disconnected

    -------------> TextCoins: Set text to "Disconned from Signalling"

    ------------+ Multiplayer: On signalling error

    -------------> TextCoins: Set text to "Signalling Error: " & Multiplayer.ErrorMessage

    ------------+ Multiplayer: On signalling left room

    -------------> TextCoins: Set text to "Partner left the room"

    ------------+ Multiplayer: On kicked

    -------------> TextCoins: Set text to "Kicked (either could not connect to host or host quit)"

    --------[Game]

    ------------[Peer]

    // When a Peer is created from 'Sync object', Multiplayer.PeerID has the ID of the peer that the object represents. This must be stored in an instance variable so we can later identify which peer the object represents.

    ----------------+ Creators: On created

    -----------------> Creators: Set peerid to Multiplayer.PeerID

    -----------------> Multiplayer: Associate Creators with peer Multiplayer.PeerID

    --------------------+ Creators: peerid = 1

    ---------------------> Creators: Set animation frame to 1

    --------------------+ Creators: peerid = 2

    ---------------------> Creators: Set animation frame to 2

    --------------------+ Creators: peerid = 3

    ---------------------> Creators: Set animation frame to 3

    --------------------+ Creators: peerid = 4

    ---------------------> Creators: Set animation frame to 4

    --------------------+ Creators: peerid = 5

    ---------------------> Creators: Set animation frame to 5

    ----------------+ [DISABLED] Creators: peerid = Multiplayer.MyID

    -----------------> [DISABLED] Multiplayer: Enable local input prediction for Creators

    ----------------+ Multiplayer: On client update

    ----------------+ [DISABLED] Creators: peerid = Multiplayer.MyID

    -----------------> Multiplayer: Set client input state "player" to value Creators.Player

    -----------------> Multiplayer: Set client input state "points" to value Creators.Points

    -----------------> Multiplayer: Set client input state "x" to value Creators.X

    -----------------> Multiplayer: Set client input state "y" to value Creators.Y

    // If the host indicates that the game state has changed, update the GameState global variable. The 'Common' group changes the display when this changes.

    ----------------+ Multiplayer: On peer message "gamestate-changed"

    -----------------> System: Set GameState to Multiplayer.Message

    ------------[Host]

    // As the host, when a peer joins we create a new paddle for them on the right. 'Sync object' will cause it to be created for the peer too. We also begin the game: we set the state to "getready" for 3 seconds, then upon "go" we set the ball moving and 1 second later set the state to "started" (so the score appears instead of "GO!").

    ----------------+ Multiplayer: On peer connected

    -----------------> System: Create object Creators on layer "Player" at (LayoutWidth÷2, LayoutHeight - 500)

    -----------------> Creators: Set peerid to Multiplayer.PeerID

    -----------------> Multiplayer: Associate Creators with peer Multiplayer.PeerID

    -----------------> Functions: Call SetGameState (state: "getready")

    -----------------> System: Wait 4 seconds

    -----------------> Functions: Call SetGameState (state: "go")

    -----------------> System: Wait 1 seconds

    -----------------> Functions: Call SetGameState (state: "started")

    ----------------* On function 'SetGameState'

    ----------------* Parameter 'state' (String)

    -----------------> System: Set GameState to state

    -----------------> Multiplayer: Broadcast tag "gamestate-changed" message GameState (from "", mode Reliable ordered)

    // There is only one other peer in the game, and we keep them positioned at the peer's "y" input, which is the Y position of their mouse.

    ----------------+ Creators: peerid ≠ Multiplayer.MyID

    -----------------> Creators: Set X to Multiplayer.PeerState(Creators.peerid, "x")

    -----------------> Creators: Set Y to Multiplayer.PeerState(Creators.peerid, "y")

    -----------------> Creators: Set Points to Multiplayer.PeerState(Creators.peerid, "points")

    -----------------> Creators: Set Player to Multiplayer.PeerState(Creators.peerid, "player")

    -----------------> TextCoins: Set text to Multiplayer.PeerState(Creators.peerid, "x") & " " & Multiplayer.PeerState(Creators.peerid, "y")

    ----------------+ Touch: On any touch start

    -----------------> System: Create object IconFingerPrint on layer "Player" at (Touch.X, Touch.Y)

    -----------------> IconFingerPrint: Set Sine Disabled

    -----------------> System: Create object IconDeflector on layer "Player" at (Touch.X, Touch.Y)

    -----------------> IconFingerPrint: Set size to (358, 512)

    -----------------> IconFingerPrint: Set opacity to 100

    ----------------+ Touch: On any touch end

    -----------------> IconFingerPrint: Destroy

    -----------------> IconDeflector: Destroy

    ----------------+ Creators: On collision with IconDeflector

    --------------------+ Creators: peerid = Multiplayer.HostID

    ---------------------> Creators: Add 1 to Points

    ---------------------> System: Add 20 to BallSpeed

    ---------------------> Creators: Set Bullet speed to BallSpeed

    --------------------+ Creators: [X] peerid = Multiplayer.HostID

    ---------------------> Creators: Add 1 to Points

    ---------------------> System: Add 20 to BallSpeed

    ---------------------> Creators: Set Bullet speed to BallSpeed

    --------[Common]

    ------------+ System: GameState = "getready"

    ----------------+ System: Game = "No"

    --------------------+ System: Every 1 seconds

    --------------------+ System: Score > 0

    ---------------------> System: Set Score to Score - 1

    ---------------------> TextDynamic: Set text to Score

    --------------------+ System: Score ≤ 1

    ------------------------+ System: Every tick

    ----------------------------+ Creators: peerid = Multiplayer.HostID

    -----------------------------> Creators: Set position to (lerp(Creators.X, 768, 0.1), lerp(Creators.Y, 924, 0.1))

    ----------------------------+ Creators: peerid ≠ Multiplayer.HostID

    -----------------------------> Creators: Set position to (lerp(Creators.X, 768, 0.1), lerp(Creators.Y, 1124, 0.1))

    ----------------------------+ Creators: Height ≥ 300

    ----------------------------+ Creators: Width ≥ 300

    -----------------------------> Creators: Set size to (Creators.Width - 15, Creators.Height - 15)

    --------------------+ System: Score = 0

    ---------------------> System: Set Game to "Yes"

    ---------------------> System: Set BallSpeed to 100

    ---------------------> System: Wait 1.0 seconds

    ---------------------> Creators: Set Bullet Enabled

    ---------------------> Creators: Set Bullet bounce off solids True

    ---------------------> Creators: Set Bullet speed to BallSpeed

    ---------------------> Creators: Set Bullet angle of motion to random(360) degrees

    ------------+ System: GameState = "go"

    -------------> [DISABLED] Creators: Set Bullet Enabled

    -------------> [DISABLED] Creators: Set Bullet bounce off solids True

    -------------> [DISABLED] Creators: Set Bullet speed to BallSpeed

    -------------> [DISABLED] Creators: Set Bullet angle of motion to random(360) degrees

    ------------+ System: GameState = "started"

    ----------------+ Creators: peerid = Multiplayer.HostID

    -----------------> TextDynamic: Set text to Creators.Points

    ----------------+ Creators: [X] peerid = Multiplayer.HostID

    -----------------> TextDynamic: Set text to Creators.Points

    Tagged:

  • Gonna need you to post your file captain

  • Gonna need you to post your file captain

    Oops! Here you go drive.google.com/file/d/1UJIOhRcpdYE-ZVxueC6tSjzjxoSdoWau/view

  • dop2000 Will you be able to you help me on this?

    Thanks in advance.

  • I can't open the file

    I get this message:

    Failed to open project. Check it is a valid Construct 3 single-file (.c3p) project.

    Error report information

    Type: unhandled rejection

    Reason: Error: invalid function name 'SetGameState' Error: invalid function name 'SetGameState' at t.ǃm$$ (https://editor.construct.net/r180/projectResources.js:1:307140) at t.ǃdY (https://editor.construct.net/r180/projectResources.js:1:307054) at Object.ǃmmz (https://editor.construct.net/r180/projectResources.js:1:331735) at t.accept (https://editor.construct.net/r180/projectResources.js:1:261270) at t.accept (https://editor.construct.net/r180/projectResources.js:1:297541) at t.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:283340) at t.accept (https://editor.construct.net/r180/projectResources.js:1:261286) at e.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:268614) at e.accept (https://editor.construct.net/r180/projectResources.js:1:261286) at e.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:268614)

    Stack: Error: invalid function name 'SetGameState' at t.ǃm$$ (https://editor.construct.net/r180/projectResources.js:1:307140) at t.ǃdY (https://editor.construct.net/r180/projectResources.js:1:307054) at Object.ǃmmz (https://editor.construct.net/r180/projectResources.js:1:331735) at t.accept (https://editor.construct.net/r180/projectResources.js:1:261270) at t.accept (https://editor.construct.net/r180/projectResources.js:1:297541) at t.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:283340) at t.accept (https://editor.construct.net/r180/projectResources.js:1:261286) at e.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:268614) at e.accept (https://editor.construct.net/r180/projectResources.js:1:261286) at e.ǃm$q (https://editor.construct.net/r180/projectResources.js:1:268614)

    Construct 3 version: r180

    URL: editor.construct.net/r180

    Date: Thu Jan 02 2020 19:01:48 GMT-0600 (Central Standard Time)

    Uptime: 2 s

    Platform information

    Browser: Chrome

    Browser version: 78.0.3904.70

    Browser engine: Chromium

    Browser architecture: 64-bit

    Context: browser

    Operating system: Windows

    Operating system version: 10

    Operating system architecture: 64-bit

    Device type: desktop

    Device pixel ratio: 1

    Logical CPU cores: 6

    Approx. device memory: 8 GB

    User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36

    C3 release: r180 (beta)

    Language setting: en-US

    WebGL information

    Version string: WebGL 2.0 (OpenGL ES 3.0 Chromium)

    Numeric version: 2

    Supports NPOT textures: yes

    Supports GPU profiling: yes

    Supports highp precision: yes

    Vendor: Google Inc.

    Renderer: ANGLE (Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0)

    Major performance caveat: no

    Maximum texture size: 16384

    Point size range: 1 to 1024

    Extensions: EXT_color_buffer_float, EXT_disjoint_timer_query_webgl2, EXT_float_blend, EXT_texture_filter_anisotropic, KHR_parallel_shader_compile, OES_texture_float_linear, WEBGL_compressed_texture_s3tc, WEBGL_compressed_texture_s3tc_srgb, WEBGL_debug_renderer_info, WEBGL_debug_shaders, WEBGL_lose_context

  • I fixed something by disabling some events in the Signalling group. I left a big comment there

    easyupload.io/qif0ie

    I don't know if it's fixed entirely though because I'm not sure what's supposed to be happening

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Noah Gengo

    Thanks alot for looking into this.

    It's my error, I should have explained more clearly.

    The peer should be created at (768, 1548) but it is being created at (0,0) and it freezes. It doesn't move like it the host. Peer functions just like the host but for some reason it is not happening in that way.

    Please let me know if you need more detailed explanation.

  • In the Host section (event 28 of your cp3) you are setting the x,y,points and player for the peer without knowing what they are, thus they revert to 0,0.

    Disable that event and actions (creators with peerid other then your own) And that camera thing will move through the screen.

    Also, you added the X,Y client input value tag with an angular interpolation, switch that to linear.

  • lennaert

    Perfect! You are right. I have made those changes and added the bullet behaviour as inputs. The game works a desired now.

    Thanks alot. :)

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