How do I send data to peers ONCE!

0 favourites
  • 2 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • I have an instance variable "gender" of object "player".

    It's basically 1 - male, 2 - female.

    I want to that number be sent to the host and back to peers when peer join a room AND NEVER AGAIN.

    How to do that ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Something like this?

    Sending your gender:

    Here when a peer connects, it first checks if the connecting peer is itself, then it sends a message to peer "", which defaults to the host, with the content of their gender id under the tag of genderMessage.

    Then, the event is called when the host receives the message, it picks the instance of the player sprite which is linked to the peer, then broadcasts the same message to all clients. After that it assigns the gender variable to the peers sprite. (This is where you'll have to make it do something).

    Finally, when the hosts broadcast reaches another peer, it checks whether the peer was the original sender and stops if it is (The original sender already knows their gender). Then for everyone else, sets the instance variable of that sprite to the gender of the original.

    Getting everyone else's gender:

    When a peer connects, the host must give it all the other connected peers' gender. The host loops through every instance of the player sprite and sends a message to the client for each player in the form "PlayerID:PlayerGender" (You could lower bandwidth by creating one string with two separators such as "Player1ID:Player1Gender,Player2ID:Player2Gender,..." but that would require a little more work on the event sheet), with the message tag "hGenderMessage".

    When the connecting peer receives one of these messages, it picks the instance of the player sprite which has the ID given in the message, obtained using the tokenat expression. Then it sets the gender of that sprite with the value of the message using the same tokenat expression, just changing the index.

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