Multiplayer questions.

0 favourites
  • 6 posts
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • Hey all,

    I'll admit multiplayer is really confusing for me atm. I've got the concepts down but having problem implementing it. Thought if some of you can help in this silly thing i've been stuck at.

    Say there are 2 sprite fonts(Lets name them SFHost and SFPeer)to be on screen,one for each player(host and peer) .to create them I synced both sprite fonts with position, so now when they are created on hosts side ,it's automatically created on the peers side.Easy

    Now i needed whatever host types to come up on SFhost and whatever peer types to come up on SFPeer. How would you go about this?. I only am able to do this successfully when the host types and not when the peer types.

    I went about giving the SpriteFonts a variable which is also synced, so when for eg. if 'A' is pressed the spritefont's variable becomes 'A 'and an event to set Sprite font's text to it's variable successfully changes the Sprite font's text. This is successfully shown on host and peer's side but when i type as peer, nothing happens.

    In other words, i don't know how to implement the client input value tag or on client update actions for this case. I have not set any peer.ids or host.ids , i just synced positions and variables and i have read all the multiplayer tuts.

    Anyone got any clue?.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you tried calling functions from host to peer and vise versa. Its much easier (specially when you game is only 2 players) and gives a fair amount of control.

    Heres and example CapX of calling functions cross device


    Just open up two browsers. Click connect on both and then type in the chat box and click send. the corresponding sprite fonts will be updated

    Hopefully it helps

  • troublesum

    Thanks a bunch, your capx helped a lot in understanding multiplayer. I was able to get my capx to work.

    I have a few questions if you don't mind.

    Imagine the same capx example as yours, but with synced spritefonts, so we can delte the sprite font on peer's side and when the spritefonts are created on hosts side , they automatically appear on peer's side.

    Now say the spritefonts have variables(which are also synced) and the text of the spritefont's are set to whatever the variables are. So if the spritefont's variable was "ABC" , the spritefont's text is "ABC".

    So now on peers side i put an event where similar to yours it sends the text box text as a multiplayer meesage, now on host's side i put an event to set the spritefont's variable to multiplayer.message that was received. Now this will update the spritefont's variable which will in turn updates the spritfont's text which in turn will update it for the peer as well.

    Now this method had the drawback of lag on the message appearing on the peers side, but do you think it reduces the number of events necessary. Tbh when i saw your capx i was so confused at first and took time to understand why so many events were needed.

    Thanks again for your help.

  • Have you gone through the Multiplayer tutorials? They describe in principle how data syncing works: the host informs the peers of the game state, and the peers inform the host of their inputs.

  • Pandy yah my event sheets tend to look over complicated (I get that a lot). I'm also lazy with not commenting my code very well. Anyway you have to keep in mind that sometimes the simplest solution is not the best (seriously). It might seem like its really easy to just associate an object and have the host create it but you wind up losing flexibility in the process. I create functions for every (and I mean EVERYTHING). From spawning sprites to setting attributes to moving players object to fire projectiles to you name it (EVERYTHING). Nothing happens in my code that isn't called from a function. By doing this I can and do sync every action across all peers with functions no matter who initiates the function. But keeping to what Ashley said some functions are only ever called by the host depending if they are game state events like a point was scored or a hit was registered. IE the peer may signal that he fired a shot and from where but after the shot is fired, only the host is allowed to determine if it made a hit and will call a function on all peers to let them know a hit was made.

    Anyway with all that said I cant really help you with what do when you sync objects as I don't code that way. What I would try to do is reduce more of your code to small functions (spawning sprites, destroying sprites, setting text.. etc) and call them on both devices simultaneously as in the example. It will take some time to get used to but you wind having the control your looking for.

    To give proof of concept (and provide more complicated code) here is multiplayer platform example that uses nothing but functions. There is some fancy stuff in there that persists functions related to movement to reduce network overhead and lag (you will notice my object have almost not lag) but you will get the idea of how I use functions for everything.


    Edit: For got to mention you will need the moveto plugin by rex to use it. I assume most people have that plugin by now

    Same as before just open 2 browser windows enter the room name and player name in each and click connect. once both players are in use the arrow keys to move them around. (supports only 2 players per room or it will break)

  • troublesum

    Oh wow thanks, you really know your multiplayer. I'll check out the capx and i'll try to get the habit of using functions. Expect the odd pms from me now if i get stuck in anything. If you don't mind that is.

    Thanks again.

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