Announcement

Collapse
No announcement yet.

Script Mystery

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

    Script Mystery

    It's been about 10 years since I've done any real VB.NET programming and this is my first real stab at it in HS3. At this point I think I've got tunnel vision and perhaps a different set of eyes would be helpful. I am trying to make a script that will cycle through the scenes I've created for a particular room. I used a naming convention to help make this a little easier. Scenes for the bedroom begin with "br ", as in "br Deep Sea". Or "fr Deep Sea" for the family room.

    If I can successfully get this one working, then I'll make one to cycle in the other direction. The problem I am having is that with each run of the script, a scene is skipped. So I'm just getting every other scene. The script is properly recognizing when it's at the top of the list and starts back at the beginning. No matter what I try it will either skip a scene or just stay on the same scene. Any insight would be greatly appreciated.

    Code:
    Imports System.Collections.Generic
    Imports System.IO
    
    Sub Main(ByVal Parm As Object)
        Dim currscene As String = hs.GetVar("brscene")
        Dim nextscenenum As Integer = 0
        Dim scenes() As String = hs.PluginFunction("JowiHue", "", "GetScenes", Nothing)
        Dim maxscenes As Integer = scenes.GetUpperBound(0)
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim roomscenes As New List(Of String)
        For x = 0 To maxscenes
            Dim scene As String = scenes(x)
            If Left(scene, 3) = "br " Then
                roomscenes.Add(scene)
                y = y + 1
                If scene = currscene Then
                    nextscenenum = y
                End If
            End If
            If x < maxscenes Then x = x + 1
        Next
        Dim maxroomscenes As Integer = y
        Dim startscene As Integer
        Dim z As Integer
        If nextscenenum > 0 Then
            If nextscenenum > maxroomscenes Then
                startscene = 1
            Else
                startscene = nextscenenum
            End If
        Else
            startscene = 1
        End If
        hs.PluginFunction("JowiHue", "", "StartScene", {roomscenes(startscene)})
        hs.SaveVar("brscene", roomscenes(startscene))
    End Sub

    #2
    Don't increment your loop counter (x). It will increment for you in the loop.

    Delete this line : If x < maxscenes Then x = x + 1

    Quick guess on my part, others are better then me at this

    Chris

    Comment


      #3
      Unfortunately that gets me right back to the problem of not advancing at all. This is really the craziest thing I've seen in a while. Jump by two or stay put. I guess I've have to pick up a little more on putting in some debug code so I can see what exactly the loop is doing.

      Comment


        #4
        Originally posted by EarlyMorningHours View Post
        Unfortunately that gets me right back to the problem of not advancing at all. This is really the craziest thing I've seen in a while. Jump by two or stay put. I guess I've have to pick up a little more on putting in some debug code so I can see what exactly the loop is doing.
        EarlyMorningHours,

        Your value of startscene is never hitting the first scene in the array, you are setting it to one, where the index starts at 0.
        I took the bite and rewrote your script so it will work. Ask any question you want if things are unclear on why it is done this way?

        Code:
        Sub Main(ByVal Parm As Object)
            Dim currscene As String = hs.GetVar("brscene")
            Dim scenes() As String = hs.PluginFunction("JowiHue", "", "GetScenes", Nothing)
            Dim roomscenes As New List(Of String)
            For Each scene As String In scenes
                If scene.StartsWith("br ") Then
                    roomscenes.Add(scene)
                    If scene = currscene Then y = roomscenes.count ' count is always one higher then the reall index, which starts at 0!
                End If
            Next
            If y >= roomscenes.count Then y = 0 'índex starts at 0, Not at 1!
            hs.PluginFunction("JowiHue", "", "StartScene", {roomscenes(y)})
            hs.SaveVar("brscene", roomscenes(y))
        End Sub

        Thanks,

        Wim
        -- Wim

        Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

        1210 devices/features ---- 392 events ----- 40 scripts

        Comment


          #5
          I apologize for such a delayed response. Thank you Wim.. very much for getting me on the right track. It took quite a bit of time as my decade long hiatus from VB.NET really shows. I was eventually successful creating a script that will go backward and forward through a list of scenes for a particular room. It took quite a while and I'm still getting used to what some of the compilation errors mean when troubleshooting, but the gentle nudge in the right direction was what I needed and is greatly appreciated.

          Dave

          Comment

          Working...
          X