Script Syntax question

Forum to discuss MLScript plugin that enables VBScript and JavaScript scripting within MLServer3.
User avatar
hakha4
Member
Member
Posts: 88
Joined: Wed Dec 24, 2008 3:18 am
Location: Moholm Sweden
Contact:

Script Syntax question

Postby hakha4 » Sun Oct 10, 2010 3:17 am

Hi!
I have a scene showing the status of relays 1 to 8 (pumps,lights etc) in the poolroom. Communication with MLGD works ok but I want to change color's of 'LED's in the scene to red = off mode,green = manual mode and blue = auto mode. I can do this with : MLCmd|{{clientname}}~setProperty|alpha~0~LED1_red~100 (ON) and MLCmd|{{clientname}}~setProperty|alpha~0~LED1_red~0 (OFF) from command line in MLServer ok. LED_redx etc are Aliase's in scene for buttons.Tried to write a script for the job but uncertain about syntax (tried a number of variants with errors). Code below don't generate error but don't work. Question 1: when using MLServer.cmdReceive or MLServer.cmdReceivePush should following command be a 'string' ?
Question 2: can someone give me a hint howto

Option Explicit
'#######################################################################
' call : MLScript|CheckPoolStatus~CheckMode~{{clientname}}~'mode'~LEDnr
'#######################################################################

Sub CheckMode (Params)
Dim Client
Dim ModeStatus
Dim LEDnr

If Ubound(Params) =3 Then
Client = Params(0)
ModeStatus = Params(1)
LEDnr = Params(2)



Select Case ModeStatus

Case "Auto" 'set red and green LED off
MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _red~0"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _green~0"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _blue~100"

Case "Manual" 'set red and blue LED off

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _red~0"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _green~100"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _blue~0"



Case "Off" 'set blue and green LED off

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _red~100"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _green~0"

MLServer.cmdReceivePush "MLcmd|" & Client & "~setProperty|alpha~0~LED" & LEDnr & " _blue~0"

End Select

End If

End Sub

Regards Håkan

ricks
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1127
Joined: Wed Oct 27, 2004 7:01 pm
Location: Latham, Massachusetts
Contact:

Re: Script Syntax question

Postby ricks » Sun Oct 10, 2010 11:39 am

There are several ways to do this but I always try to limit the number of plugins involved in any action within the system. Also, I've found that I cannot send "setProperty" commands from MLServer, only from button presses in ML scenes.

I do this same thing with my security system with a button that shows green when the security system is off and all access points secure, red when the security system is armed and yellow when it is off but at least one access point is not secure.

Since you're using MLGD you really don't need to involve another plugin. Since I'm not familiar with your device, let's assume that the device status sent to MLGD is off = 0, manual = 1 and auto = 2. So MLGD may give you variables like {{poolroom_pump_1}} with values of 0, 1 or 2.

In you scene create a button for {{poolroom_pump_1}}. I use Button 0061 at a scale of 38 %. Put a check in the "Hide Value" checkbox. In the button, place that variable in the Label Field then go to "States", leave the "Local Off Value" empty (same as 0) and set the "Off State" color to red and the "On State" color to green. Now when the pump is off it will display RED and when the pump is anything else it will display GREEN.

Now copy and paste this button and leave it directly over itself. In this second button, leave the same variable in the "Label Field" and check the "Hide Value" checkbox but in "States", set the "Local Off Value" to "Auto" or "2" (whichever value MLGD sends for auto) and set the color to Blue. Set both of the "On State" sliders to transparent (all the way off).

Result? When the variable state is Off or 0, the first button displays Red and the second button is invisible. In the Manual or 1 state, the first button displays Green and the second button is invisible. When the variable state is Auto, the first button displays Green BUT, the second button is now visible as Yellow and obscures the first button.

Since ML buttons can't do 3 state status, I've found this method to be the most reliable.

Hope it helps.

Rick

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Re: Script Syntax question

Postby ronsatter » Sun Oct 10, 2010 10:07 pm

Rick,

Excellent tutorial ... as usual =D>

Ron
If it ain't broke ... don't fix it!

User avatar
hakha4
Member
Member
Posts: 88
Joined: Wed Dec 24, 2008 3:18 am
Location: Moholm Sweden
Contact:

Re: Script Syntax question

Postby hakha4 » Mon Oct 11, 2010 11:51 am

Hi
I managed to get the script to work after a lot of trial and terror and I also found that it can't be run from the server but from a button (why?) but your solution is more elegant and I go for that,thank's alot. Despite reading forum and Wiki I think it's hard to figure out what syntax to use in different scenario's, I lack a howto for newbies with stringent explanation as in your answer,is there one that I've missed? Dare to say but I have more things I probably need help with,hope people don't mind asking so many questions.
Regards Håkan

ricks
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1127
Joined: Wed Oct 27, 2004 7:01 pm
Location: Latham, Massachusetts
Contact:

Re: Script Syntax question

Postby ricks » Mon Oct 11, 2010 2:06 pm

Glad it worked. I never had trouble getting a script to fire from MLServer but as I mentioned, setProperty commands have to be sent from ML, not MLS. Would be great to see that resolved.

Way back yonder someone had put together a "cook book" style primer. To me, that was the easiest way to learn. I still think it's around somewhere but so much has changed since then that it probably wouldn't be helpful. As is usually the case, the wiki is designed to be "plugin-centric" as opposed to "results-centric". In other words, it's easy to locate the instructions for a plugin, but it's virtually impossible for someone new to find something based on the result they are seeking. Like in your case, "How to have a button reflect 3 or 4 states."

There are plenty of folks on this forum willing to help out so don't hesitate to ask.

Rick


Return to “MLScript”

Who is online

Users browsing this forum: No registered users and 1 guest