Announcement

Collapse
No announcement yet.

tenscripting3 vs HomeSeer Native Execution differences

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    tenscripting3 vs HomeSeer Native Execution differences

    Hello all,

    When I have this line:

    DebugDest = hs.ReplaceVariables("$$GLOBALVAR:debugdest:")

    In a script in tenScripting 3 inside the Class definition but outside of a Sub or Function, it executes fine.

    When I export the script and execute in a manual test event, the line generates this error in HS3:

    Compiling script C:\Program Files (x86)\HomeSeer3\scripts\DebugTest.vb: Exception has been thrown by the target of an invocation.

    If I move that line inside the Main Sub, it will execute fine.

    Any thoughts on why that is? I really don't understand the difference.




    #2
    There was just another post about this. It turns out that you can't use global variables in direct script calls in events. See post #4 here:

    https://forums.homeseer.com/forum/te...vicevaluebyref

    Comment


      #3
      Originally posted by mulu View Post
      There was just another post about this. It turns out that you can't use global variables in direct script calls in events. See post #4 here:

      https://forums.homeseer.com/forum/te...vicevaluebyref
      I don't see the connection. I'm not using the function in an immediate script, just a normal HS3 script. Perhaps I'm missing something in your link.

      Comment


        #4
        mterry63 - You have an extra ")" at the end of your statement. Try removing that.

        DebugDest = hs.ReplaceVariables("$$GLOBALVAR:debugdest:")

        Comment


          #5
          Originally posted by kenm View Post
          mterry63 - You have an extra ")" at the end of your statement. Try removing that.

          DebugDest = hs.ReplaceVariables("$$GLOBALVAR:debugdest:")
          Sorry, that was a copy/paste error from the original text.

          As I stated, the command works in the tenscripting3 environment, but not when the script is exported. I'm trying to understand why that is. I'm not making any syntax changes during the export. Perhaps tenholde will weigh in.

          Comment


            #6
            tenScripting attempts to duplicate as closely as possible the HS scripting environment to facilitate testing. This is not 100% possible. As the OP notes, something like:
            Code:
            Class TestScript5
            Dim Upt As String = hs.SystemUpTime
            Public Sub Main(ByVal Parms As Object)
            hs.WriteLog("test msg", Upt)
            End Sub
            End Class
            works fine in tenScripting but will create an error when exported and run in the HS scripting environment. tenScripting is just a Visual Studio solution, and the scripts being tested are compiled by the visual studio compilers. tenScripting creates separate classes out of each script so that VS will compile it such that when tenScripting is run, it can load a specified class (script) and execute it.

            HS does unknown things with your script before invoking a Microsoft compiler to process it, including adding several statements to the beginning of your code (that is why the line number in error messages are incorrect).

            Not knowing what HS is actually doing, and based upon the generic error message, I can only guess what might be happening. I suspect that the hs object created and made available to your script code is not available outside of the invoked script (Main). I do not know why this might be, but when I change the statement outside of the SUB to: Dim Upt as String = "hello world" all works fine.

            tenScripting creates hs as a global variable that is available throughout your code, so the reference to hs works in tenScripting outside of the Sub Main. [as an aside, when I added support for C#, I ran into a similar issue in that C# does not allow true global variables the way that VB does. For a C# tenScripting script, it is necessary to add a statement creating the hs variable in every C# SUB and FUNCTION. The statements are removed during exporting to HS. So how does HS make the hs variable available to C# SUBs? Perhaps they are adding the declaration statements to both VB and CS SUBs, in order to make hs available, which would explain why you cannot reference hs outside of the SUB]

            Sorry for the long, rambling post. Hope it is helpful
            tenholde

            Comment


              #7
              I appreciate the detailed response. It's always helpful to understand why things work the way they do. Enjoying working with your tools and utilities.

              Comment

              Working...
              X