What's New in Director 8.5 > Multiuser Server-Side Scripting > Adding server-side scripts > Sending custom events to server-side scripts

 

Sending custom events to server-side scripts

To call a handler in a movie's server-script, send a message with "system.script" in the #recipients parameter and the handler name in the #subject parameter. The following statement sends a message to the server that calls the handler testHandler in the movie's server-side script:

errCode = gMultiuserInstance.sendNetMessage([#recipients: \
"system.script", #subject: "testHandler", #content: \ 
"This is the text to be displayed"])

The movie's server-side script will receive this message, and its on incomingMessage handler will be called. The on incomingMessage handler should contain a case statement that tests the contents of the #subject property and calls the handler named in it.

The server-side script would look something like this:

on incomingMessage (me, movie, group, user, fullMsg)
	-- if the #subject of the incoming message is "testHandler",
	-- call that handler and pass it the #content as an argument
	case fullMsg.subject of 
		"testHandler":
			me.testHandler(fullMsg.content)
	end case
end
	
on testHandler me, textArg
	-- display the #content of the message in the server's
	-- console window
	put textArg
end

Note that the arguments me, movie, group, user, and fullMsg are provided by the server and must be included with the incomingMessage handler. By passing these arguments to your handler, the server lets you know exactly who the message came from.

Specifying "system.script" as the recipient tells the server to send an incomingMessage event to the server-side script associated with the movie that sent the message. The #subject gets passed to the handler as part of the argument fullMsg. The put statement in the handler causes the server to display the specified text in its console window.