No announcement yet.

Same script for Device Button and Event?

  • Filter
  • Time
  • Show
Clear All
new posts

    Same script for Device Button and Event?

    It looks like a Device Button Script will only work with a script declared as
    Sub Main(ByVal parms() As Object)
    while an Event Script will only work with a script declared as
    Sub Main (ByVal parms As Object)

    After lots of permutations, I was not able to make one script that would handle being called by both a Device Button and an Event. Instead I put this 'frontend' script on the Device Button

    Sub Main(ByVal parms() As Object)
    'parms(0) is the device reference that called this script, you can use it in the RunScriptFunc call if you need it
    'parms(1) is the object that was inserted in the "ScriptParm" field of the "DeviceScriptButton_AddButton" definition of the device button
    ' parms(1) should be of the format: <scriptname to call>!<parameter string to pass to that script>
    ' the "!" is required between the name of the script and it's parameter string, even if the parameter string is empty
    Dim newScriptToCall() As String = parms(1).ToString().Split("!")
    If newScriptToCall.Count <> 2 Then
    hs.WriteLog("Button<br>Generic<br>Script.vb<br>Error","Unexp ected format parms(1)=" & parms(1).ToString())
    ' hs.WriteLog("Button<br>Generic<br>Script.vb", "Calling RunScriptFunc, " & newScriptToCall(0) & ", " & newScriptToCall(1))
    hs.RunScriptFunc(newScriptToCall(0),"Main",newScriptToCall(1 ),False,False)
    End If
    Catch ex As Exception
    hs.WriteLog("Button<br>Generic<br>Script.vb<br>Error", "Unknown Error: " & ex.message)
    End Try
    End Sub 'Main

    Surely there is a more elegant approach?

    I found it very strange that the calling sequence is different from HsTouch and the scripting engine.

    I, too, tried several ways to make them consistent, to no avail.

    I added an option in tenScripting so that when you debug a script, it can pass the parameters to your script either way.