Messagerie de jeu
Des données peuvent être échangées avec un appareil sans fil, sur un canal indépendant du shell normal. Le cas d'usage par défaut est l'application mobile pendant les parties, mais la messagerie permet aussi d'interagir avec un ordinateur via le Command Center.
- Tout message commençant par '>' est traité par la messagerie de jeu.
- Elle peut contenir jusqu'à 20 messages dans une FIFO.
- Les messages peuvent faire jusqu'à 100 octets.
- Le caractère d'alerte (Bell, Beep) '\a' ne doit PAS être utilisé dans les print ou dans les messages.
Exemple
Envoyez leds #RRGGBB depuis le Command Center pour changer la couleur des LEDs, et exit pour arrêter.
import olem
def parse_msg(msg):
argv = msg.split()
argc = len(argv)
if argv[0] == "leds":
if argc < 2:
print("Not enough args for leds command")
return
if argv[1][0] != '#':
print("Command leds expects a hex color (#RRGGBB) as 2nd arg")
return
olem.led_on(olem.LEDALL, argv[1])
else:
print("Unknown command")
print("start gmsg basic testing")
msg = "no msg received"
while "exit" not in msg:
msg = olem.gmsg_wait_for_message()
parse_msg(msg)
print("end gmsg basic testing")
Fonctions
gmsg_wait_for_message()
Wait for a message from the mobile app or the Command Center. The game can still be stopped during the wait.
Received messages are kept in a queue of up to 20 messages.
Returns: the oldest message received
gmsg_wait_for_message_timeout(timeout)
Wait for a message from the mobile app or the Command Center, for a limited time.
| Parameter | Description |
|---|---|
timeout | maximum time to wait in ms |
Returns: the oldest message received, or an empty string if no message arrived in time
gmsg_send_message(message)
Send a message to the mobile app or the Command Center.
| Parameter | Description |
|---|---|
message | text of up to 100 bytes. Do not use the alert character "\a". |
gmsg_reset_queue()
Delete the received messages that were not read yet.
gmsg_get_message()
Get the oldest received message, without waiting.
Returns: the oldest message received, or an empty string if there is none
gmsg_get_waiting_message_count()
Returns: number of received messages that were not read yet