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.
Announcement
Collapse
No announcement yet.
tenscripting3 vs HomeSeer Native Execution differences
Collapse
X
-
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
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
Leave a comment:
-
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.
Leave a comment:
-
Originally posted by mulu View PostThere 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
Leave a comment:
-
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
Leave a comment:
-
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.
Tags: None
Leave a comment: