# callback\_ReceivedMessage

After a successful message send on your server, the callback function **callback\_ReceivedMessage()** is called. So under Scripts/Rocket Networking/Callback Functions , you can edit this to do whatever you want…

### Example Implementation of callback

<figure><img src="/files/fn3L5kUz14j4YwhaSnH5" alt=""><figcaption></figcaption></figure>

* In a shooter game, if you hit another player, you want to inform them that their health reduced right?
* You can send a message called "damage"
* The receiver can see the message and use the switch statement to reude their player's health by 10 if the message is "damage"

```

function callback_ReceivedMessage(theMessage , senderClientId){
	switch(theMessage){
		case "damage":
		oPlayer.myHealth -= 10
		if(oPlayer.myHealth <= 0){
			show_message("YOU DIED")
		}
		break;
	}

}
```

## More Complex Systems

As I talked about a switch statement here, you can make a full event based system encoded in the message.

To do that, you can make a struct and stringify it and send it over to the reciever.

```
var structToSend = {
    eventName : "damage",
    value : 10
}
SendMessageToClient(5 , json_stringify(structToSend))
//this sends a strigified version of that struct to client id 5
```

On any reciever's screen, you have to reduce the health right? So you can do this in the **calback\_ReceivedMessage()** script

```

function callback_ReceivedMessage(theMessage , senderClientId){
	var realData = json_parse(theMessage)
	switch(realData.eventName){
		case "damage":
		oPlayer.myHealth -= realData.value
		if(oPlayer.myHealth <= 0){
			show_message("YOU DIED")
		}
		break;
	}

}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rocket-networking.gitbook.io/docs/rocket-networking-code/private-messaging/callback_receivedmessage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
