Name
CreatePort -- create a message port for your script (V5.0)
Synopsis
CreatePort(name$)
Function
This function will create a message port for your script and assign the specified name to it. In order to receive messages sent by SendMessage(), your script needs to have a message port. Other Hollywood applications can then communicate with your script by sending messages to this port. All messages that arrive at your message port will be forwarded to the callback function which you need to install using the InstallEventHandler() function (use the OnUserMessage event handler). If you do not install this event handler, you will not get any notifications on incoming messages.

Please remember that message port names are always given in case sensitive notation. Thus, "MYPORT" and "myport" denote two different message ports. For style reasons it is suggested that you use only upper case characters for your port name. Furthermore, each message port must be unique in the system. If you specify a port name which is already in use, this function will fail. Thus, make sure that you use a unique name.

Please note that every Hollywood script can only have one message port. If you have already created a message port and call this function again, the old message port will be deleted.

See InstallEventHandler for more information on how the user callback function will be called.

Inputs
name$
desired name for your message port
Example
Function p_EventFunc(msg)
  Switch msg.action
  Case "OnUserMessage"
    Switch msg.command
    Case "EXIT"
      DebugPrint("Exit received! Quitting now.")
      End
    Default
      Local t = SplitStr(msg.args, "\0")
      DebugPrint(msg.command, "called with", msg.argc, "argument(s)")
      For Local k = 1 To msg.argc
         DebugPrint("Argument", k .. ":", t[k - 1])
      Next
    EndSwitch
  EndSwitch
EndFunction
CreatePort("MY_COOL_PORT_123")
InstallEventHandler({OnUserMessage = p_EventFunc})
Repeat
  WaitEvent
Forever
Save the code above as a Hollywood script and run it with Hollywood. Then save the following code as a new Hollywood script and run it:


SendMessage("MY_COOL_PORT_123", "INIT", "Value1", "Value2", "Value3")
SendMessage("MY_COOL_PORT_123", "DO_SOMETHING", "Argument1")
SendMessage("MY_COOL_PORT_123", "EXIT")
The code above will then communicate with the first script. You can see that the messages are arriving from the debug output of script number one.

Show TOC