How do I sync text in multiplayer? How di I sync correctly for a simultan game?

1 favourites
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hi guys,

    I've connected peer to host and the sprites got sync. But the container with the text does not sync.

    First I put the text from csv into an array.

    The time the game starts (host & peer connected) the function "spawnF1vs2" spawns blocks with text. The text ist set from an array.

    Then I try to sync the blocks (spranswer) and their text (txtanswer). The text is in a container with the block.

    On the host side it works normal.

    But on the peer side the blocks are not at the correct size, the text container isn't there and it spawns additional blocks.

    I'm a little bit confused. So what do I exactly need to sync if both players should play with the blocks at the same time?

    this is the c3p file: transferxl.com/08jjBF20vBMfww

    You only need the layout "multilogin" to start. Insert a name and it switches to the "1vs1multi" Layout. The Event Sheets for these two are "Event Login Events" and "Event 1vs1multi".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Haven't looked at your project yet (the filesize is rather large), but some possible issues:

    The sync action only syncs object creation, destruction, and optionally angle and position. Any resizing of the object will need to be manually done on both the host and peer and synced. You can either use consistent events between the host and peer (non host-authoritative) to do so, or put the information in a synced instance variable (host authoritative) and update the values on the host which peers read and adjust the object accordingly.

    Make sure the peer isn't running the spawn function, only the host should create or destroy any synced objects.

  • Thanks for your answer!

    I think my biggest problem is to understand the method of multiplayer.myid .peerid and the sync and associate stuff in english. Since some weeks i look every video and I don't know how often I read the tutorials for multiplayer. and the sync doesn't work :(

    I thought it was much simpler to sync.

    Because the only thing to do is to connect 2 players.

    then spawn the sprites and the random text.

    both player only have their mouse for drag&drop the sprites and click a button if they found a pair.

  • peerid is used as a unique identifier for each person, while myid gets their own.

    You probably don't need to associate if each player isn't controlling a single object.

    Sync object is something the host does. Once an object is synced, if this object gets created or destroyed by the host, create it and destroy it on all connected peers (same for position and angle, if selected).

    So if the host moves a synced object, it will move the same way on all peers.

    Peers cannot move the synced object. They can only tell the host what they are doing with their mouse and keyboard inputs, and then the host can move it based on that.

    This will cause what appears to be input delay/lag on peers. You can hide this lag on the peer side by using "local input prediction".

    Multiplayer concepts definitely take more than the usual effort to learn, even if the game itself is simple enough.

  • Thanks again. I'm trying hard to understand :D

    I've made a very very smaller c3p file just for understanding how to sync back from peer to host. maybee you can help on that small file better.

    transferxl.com/08jJhJ6BpxBJMJ

  • Damn! I don'T get it worked for both sides. The peer sees the movement. but the host does not update the peers movement.

    C3p: transferxl.com/08jJhJ6BpxBJMJ

  • Ok there are a few issues here...

    You only have one input value, at very low precision. This can only contain a 1 byte value, which is a single number between 0 and 255. A 1 byte value can also be represented in binary to simulate 8 on/off switches - this is how they used it in the multiplayer tutorial. With it, they can keep track of up to 8 keys or mouse buttons that are being pressed or not.

    However, consider your own needs. What does the peer need to tell the host? In your game, you'll need to send the fact that the peer clicked, and also where the peer clicked. The location is two values, an x and a y number, that can definitely go above 255. So these two values need a higher precision. I would use normal or high, since you're honestly not going to have bandwidth concerns with just two players and small amounts of data going back and forth.

    So step 1, add two more input value tags, for "mouseX" and "mouseY", precision high, no interpolation.

    You probably also don't need to store the peer values as instance variables in the object, since I'm assuming you may have multiple cards eventually, and either player can move them so the peer inputs are not associated with any particular card. So you can get rid of the sync variable, and use the inputs directly to keep it simpler.

    -> Multiplayer: Add client input value tag "inputs", precision Very low (uint8, 1 byte), interpolation None
    -> Multiplayer: Add client input value tag "mouseX", precision High (double, 8 bytes), interpolation None
    -> Multiplayer: Add client input value tag "mouseY", precision High (double, 8 bytes), interpolation None
    

    Next lets look at the peer events, to send the peer inputs to the host. Lets remove local input prediction for now, since you haven't gotten the underlying system working yet. Since you're only keeping track of 1 button press, left mouse down, you don't even have to worry about setting bits. So keep it simple. If left button is down, set inputs to 1. Else 0. You'll also always want to send your current mouse position every update, so you need to add

    + Multiplayer: On client update
    -> Multiplayer: Set client input state "mouseX" to value Mouse.X
    -> Multiplayer: Set client input state "mouseY" to value Mouse.Y
    ----+ Mouse: Left button is down
    -----> Multiplayer: Set client input state "inputs" to value 1
    
    ----+ System: Else
    -----> Multiplayer: Set client input state "inputs" to value 0
    

    Your peer events should have nothing else for now. Remember the peer only tells the host what its inputs are, the host will do all the work and sync back the results to the peer.

    As for your host events... the "On client update" is a peer only trigger. So basically your host is doing nothing at all right now. Again, the host needs to do the actual work of moving of the object based on peer inputs.

    So first it needs to have its own way of moving the object. The drag and drop behavior should be enough for this for now.

    Secondly, it needs to check if the peer's mouse is down. If it is, then is it clicking on the sprite? Then after that, if it is clicking and on top of a sprite, update the sprites position every tick to wherever the peer's mouseX and mouseY are.

    At this point, if you've got everything working properly, both players should be able to move the object around with their mouse. You can try adding lag compensation after you get this working.

  • Oh ossyrag, you're a genius! so many thanks :)

    I think it's a problem of my bad english to understand more complicated things.

    With this code both player can move the sprite and it is updating at both screens it's position.

  • Can I ask another question?

    I've now a block with a text. this text is in a container with the block. and the text comes from an array.

    while the blocks and text spawn correctly at the host side, the text is not displayed at the peer side.

    when I try to sync the text addiotnal to the block, the blocks spawning two times. this seems to be because of the conatiner.

    So how do I get the textobject synced?

    The host triggers the function:

    The host side has all informations

    the peer side gets no informations

  • I avoid containers in multiplayer. I believe that's an old bug, unlikely to be fixed in the near future.

    Just sync and create both objects together.

    Regarding passing the information, remember sync only syncs creation, destruction, position, and angle. For everything else, you can have the host send a message, or sync an instance variable. The peer will then need to set the content of the text object based on the received message or synced instance variable.

    Also after you get your host and peer communicating, you probably want to implement local input prediction to deal with the lag. Just enable it on the object the peer is trying to move, and have the peer move it in the exact same method the host would. You probably will need to add checks to prevent the host and peer from moving the same object at the same time as well.

  • Hi,

    I've got it worked for 1 instance if I broadcast with messages. I read that strings can't be synced, so I used the messages. But I think I doing it wrong.

    1.) I spawn a block and a text. Pin the text to the block. Set the text to a value from an array. and set the text instance variable (txtanswerinhalt) to the value of the text. That works fine. Each instance of the text has it's own Text like it should.

    2.) then I try to sync the text instance variable to the peer. So I send it via broadcast with tag. To get sure I get all txtanswerinhalt from all text instance I use system->pick all instances

    3.) On message I set the text instance variable (txtanswerinhalt) at the peer side to the value of the message and then the text object value to the new value of txtanswerinhalt.

    The problem is now that it does it only for one text. It doesnt pick all text objects at the peer side to update with the new values. So it show the same text at all text objects.

    Can you fix this?

    And maybe I should send you a job offer. What will it cost to hire you to make this multiplayer run?

  • I would use a synced instance variable, assuming both the peer and host have access to the same array.

    Host side -

    On creation of the text object, how are you setting the text from the array? I assume you're using some sort of index. Save this index number (location in the array where your text is) to the synced instance variable for that text object at the same time you set the text value from the array.

    Peer side -

    The text object will get created, and it will have the synced instance variable referencing the correct text for itself. Use that instance variable either on created or other trigger of your choosing to reference the array to grab the right text.

    I'm not comfortable taking paid work, as I would not be able to make a time commitment for it, nor am I 100% positive I'd be able to solve any issues that come up. Multiplayer is really difficult to design for. I don't mind throwing out ideas here on the forum as usual though.

  • Oh, that works fine. and so easy! I've done this before in an other scenario. Why I didn't get this by myself :D

    So the last thing I need is to improve the performance. The host now has almost around 10 Frames, the peer around 50.

    At the peak there will be around 75 blocks + their 75 text objects. How can I get a good performance in the multiplayer mode?

    So if you don't wanna work for me :D - Can I get you a coffee or donation somewhere?

  • Fps is hard to diagnose in any project, but I don't imagine yours would be resource intensive. First thing I usually do is to change any event that runs every tick to have a trigger instead if possible. Updating text objects every tick can be a huge one. Second is to look for big loops that can be optimized. Is your original download link up to date? I can take a look when I get a chance.

    I would always appreciate a drink.

    paypal.me/oosyrag

  • Yes, I've seen that problem. I've tried to use enable local input at the peer side. But then the position of the blocks do not sync correctly. In the version I upload now the sync is okay, but it seems laggy for the peer.

    If you download the c3p File, u only need the "multilogin" Layout for start a test. All events are placed in Multiplayer-->Event sheet "1vs1multi".

    I've also added a test for photon plugin. Works fine, but too expensive if there are too many players :(

    transferxl.com/08jG9VD5w7ph1B (430MB)

    Here's an roadmap of the way the data comes in:

    1.) The time the block is create it also creates the text object (Under Group "Spawns2")

    2.) then it gets its value from the array (arr_1vs1right or ...left) randomly, depending on a random number (randomwithrigt/left)

    3.) the array gets its values at Start of layout from the files "serienchars.csv"

    4.) If text is created it sets its instance variables. I need esp "syncarray"

    5.) Under "Peer"Group the text objects gets their value from this variable

    6.) Now, if Left button is down at the peer, it sets "inputs" to 1

    7.) On client update it sets the coordinates of the mouse while dragging.

    8.) On "Host"Group there might be the problem with the "every tick" events. It updates the coordinates every tick and - if "inputs" =1 comes from the peer - sets the new position

    The focus on these events is to sync the coordinates of the blocks and pinned text, so that both player see where they are. This is nede because they want to find matching pairs in the game. So they need to see what the other player is doing.

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