Go to documentation repository
The CreateMsg method creates objects based on the MsgObject prototype (see The MsgObject and Event objects).
Syntax for method invocation:
function CreateMsg() : MsgObject
There are no method arguments.
Example 1. When an alarm is received, send the “panic lock” event for the corresponding region of the camera. If the identification number of the alarm camera is from 1 to 4, use region 1. If the identification number of the alarm camera is from 5 to 10, use region 2.
if (Event.SourceType == "CAM" && Event.Action == "MD_START") { var msgevent = CreateMsg(); msgevent.SourceType = "REGION"; msgevent.Action = "PANIC_LOCK"; if (Event.SourceId <=4) { msgevent.SourceId = "1"; } if ((Event.SourceId > 4) && (Event.SourceId < 10)) { msgevent.SourceId = "2"; } NotifyEvent(msgevent); }
Example 2. When timer №1 starts, start macro 1 every 30 seconds.
Note
To start this script, you must create the Timer object with the identification number 1 beforehand. Set value 1 to the Second parameter of the Timer object, leave other parameters unchanged (Any by default).
if (Event.SourceType == "TIMER" && Event.SourceId == "1" && Event.Action == "TRIGGER") { var msg = CreateMsg(); msg.StringToMsg(GetObjectParams("TIMER", "1")); if(msg.GetParam("s") == "1") { DoReactStr("MACRO", "1", "RUN", ""); SetObjectParam("TIMER","1","s","30"); DoReactStr("TIMER","1", "DISABLE", ""); DoReactStr("TIMER","1", "ENABLE", ""); } if(msg.GetParam("s") == "30") { DoReactStr("MACRO", "1", "RUN", ""); SetObjectParam("TIMER","1","s","1"); DoReactStr("TIMER","1", "DISABLE", ""); DoReactStr("TIMER","1", "ENABLE", ""); } }