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 ?
Develop games in your browser. Powerful, performant & highly capable.
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.