Callback Functions

Type
Function

Rocket Networking Callback Functions

Rocket Networking provides a suite of callback functions that are invoked under specific network events. These callbacks are essential for managing client-server interactions in your game developed with GameMaker Studio. Below is the documentation for each callback function.

image

callback_Admin

This callback function is triggered when the server needs to send an urgent message to the client, such as reaching the maximum server capacity. It should not be visible to players in the production environment.

  • Parameters:
    • alert_message: The message from the server to be displayed.
  • Usage Example:
  • 
    function callback_Admin(alert_message){
      show_message(alert_message + " This alert came from callback_Admin function. Please hide this in production!")
    }
    
    
  • Note: Always ensure that this message is concealed from the end users in the live game.

callback_ConnectToServer

Called after the client has successfully connected to the server. You can customize this function to perform any action post-connection.

  • Usage Example:
  • 
    function callback_ConnectToServer(){
      show_message("You connected as client with id " + string(global.clientId) + " at time " + string(current_time))
    }
    
    

callback_DisconnectFromServer

Invoked when a client has voluntarily disconnected from the server by calling the relevant function.

  • Usage Example:
  • 
    function callback_DisconnectFromServer(){
      show_message("You have successfully disconnected")
    }
    
    

callback_LeaveRoom

This function is executed when a client leaves a room and returns to their private room.

  • Usage Example:
  • 
    function callback_LeaveRoom(){
      show_message("Back to my private room")
    }
    
    

callback_ReceivedMessage

Triggered when a client receives a message from another client in the server.

  • Parameters:
    • theMessage: The message content received.
    • senderClientId: The unique ID of the client who sent the message.
  • Usage Example:
  • 
    function callback_ReceivedMessage(theMessage, senderClientId){
      show_message("You got a message: " + theMessage + " from " + string(senderClientId))
    }
    
    

callback_ShowAllRooms

Called when you want to retrieve and display an array of all the rooms on your server.

  • Usage Example:
  • 
    function callback_ShowAllRooms(array_of_rooms){
      show_message(string(is_array(array_of_rooms)) + "  " + string(array_of_rooms));
    }
    
    

Implementation Notes

When implementing these functions in your game, make sure to customize the behavior as needed to fit the design and flow of your game. The callback functions provide a framework for handling networking events but can and should be tailored to provide the best experience for your players.