User Tools

Site Tools


4rpl:commands:registerformsg

Index
Messaging

RegisterForMSG

RegisterForMSG(<-channel <-callbackFunction)

Description

Registers a script to receive callbacks whenever somethings sends a message to 'channel'. The channel is just a string.

Callbacks are made at the time sending happens. Note that some callbacks can be made from system objects, like the InfoCache. The callback is made to the function specified by 'callbackFunction'. It is not case sensitive. A var named “_DATA” will be set before the function is invoked on the script. That var can have any type, it depends what type the sender sent.

Messages are registered by channel. So if you call RegisterForMSG more than once with the same channel, but different callbackFunctions, only one registration is performed. Subsequent calls to register on the same channel will replace any previous registrations. Multiple scripts can register to a single channel, but a single script can only have one registration for a particular channel at one time.

RegisterForMSG is persistent, so you only need to call it once.

Examples

:once
   RegisterForMSG("test" "MyCallback")
 
:MYCALLBACK
   PrintallSP("Callback: " <-_DATA)

See also

4rpl/commands/registerformsg.txt · Last modified: 2022/11/23 13:52 by Karsten75