Messages

Using shared data for all communication between games is inefficient. It requires games to check values even if they haven't changed. Messages are useful for telling games that something has changed or something should be done.

Message ID
Every message has an id. This id lets the game know what the message is about. In order to make code more readable and allow for later changes easily it is a good idea to use constants for id numbers.

Example
Here is a example of a message loop in the begin step event with some common messages you might need or want.

/* Constants: player_change: A game sends this when it joins or leaves a session. Other players respond by relisting all players. player_kicked: The host sends this to a player when they get kicked from the session. The value is player ID, corresponding player leaves and sends player_change message to other players. */ while(mplay_message_receive(0)) {  switch(mplay_message_id) {    case player_change: mplay_player_find; break; case player_kicked: if(mplay_message_value=mplay_player_id) {        mplay_message_send(0,player_change,0); mplay_session_end; }    break; } }