Don't use alert or anything else that waits when receiving network messages. It means that while it's waiting, other messages can arrive and overwrite the current message. It should always work fine if you avoid alerts/waits.
I continued to experiment with the functionality of the Multiplayer object, and found another problem that was a bit stranger than the one in the previous posts.
I'm attaching an image so you can better understand my situation:
(the two functions set variables and create objects. They don't have any event of "Wait" or similar)
The events you can see are executed only by the peer, and the various events of sending messages to the host are executed when your Player objects have been correctly created (the sub-event of the "On created" event is executed only when the second Player object (there are 2 Player objects in total) is created.
The problem occurs randomly, as some times everything is executed correctly, while others I've noticed two types of errors occurring randomly and separately:
- In the first sub-event, the two functions are not executed, but the "pg" message is still sent.
- In the event of receiving the "pg" message from the host the Player pick is not executed because through an Alert of Player.Count the result is 1 (this should not be possible since the previous message of the above event is sent only if the second Player has been created)
By inserting those two "Wait" events it seems that the errors occur less times, but still they occur very often.
Since some times the code works correctly, I can't figure out where the error is and what it is caused by.
I thought that the ids present in the Multiplayer object sometimes were not correctly accessible, and I tried to save them in a variable, but the result did not change, so the problem does not lie there. I have also checked several times that the Player.peerID variables are correctly assigned, and each time the variables are correct.
Finally, I would like to point out that every time the problem occurs, both Players are on screen correctly, although a few times the Alert with Player.Count returned me the value 1.