Announcement

Collapse
No announcement yet.

Named subroutine behaves different than "main"

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

    Named subroutine behaves different than "main"

    I just modified a script of mine to have two subroutines rather than just the single main() subroutine. The structure was:

    sub main()
    ...
    end sub

    Now I've got:
    sub SetAlarmFor(Nulldata)
    ...
    end sub

    sub AlarmSetFor(Nulldata)
    ...
    end sub

    The SetAlarmFor() subroutine was the "main()" subroutine before. It was a VR activated script with a VR confimation for yes or no. When I changed the sub from main to SetAlarmFor, the VR confirmation broke. It does not wait for the VR command (yes/no). It recognized "goodbye" even though the system.ClearAllVoiceCommands is issued in the script.

    The strange thing is, when I name it back to "sub main()", everything works fine.

    Am I crazy??

    Thanks,
    Doug Woolridge

    P.S. I call the routine from a VR event with the following script command:
    SetAlarmForPerson-DDW.txt("SetAlarmFor","")

    With just "sub main()" I call it with:
    SetAlarmForPerson-DDW.txt

    #2
    You need a sub main() in the script file whether you call it or not. It can be as simple as:

    sub main()
    end sub

    If that is not the problem, I don't have an answer. I have a lot of scripts where I do this and I've never had a problem with it that I know of.

    Bill

    Comment


      #3
      Thanks for the suggestion Bill, but I had already tried that.

      SetAlarmForPerson-DDW.txt("SetAlarmFor","")

      sub main()
      ' Nothing here
      end sub
      sub SetAlarmFor(Nulldata)
      ...
      end sub
      sub AlarmSetFor(Nulldata)
      ...
      end sub

      I'm not sure if it has to do with the "main" subroutine or the fact that I'm passing parameters to the script.

      I'm going to try changing "sub SetAlarmFor(Nulldata)" to "sub main(nulldata)" and call it using:
      SetAlarmForPerson-DDW.txt("main","")

      If that doesn't work, there must be an issue with VR and passing parameters to scripts.

      Comment


        #4
        You can only pass one parameter. If you need more than one, you can make them global, or string them together in the call and break them apart in the routine / function

        Comment


          #5
          I don't actually need to send any parameters. I just want to call different subroutines in my single script file directly from a Homeseer event.


          Calling the script with...

          SetAlarmForPerson-DDW.txt

          sub main()
          SetAlarmFor code here
          end sub
          sub AlarmSetFor()
          ...
          end sub
          --WORKS

          SetAlarmForPerson-DDW.txt("main")

          sub main()
          SetAlarmFor code here
          end sub
          sub AlarmSetFor()
          ...
          end sub
          --DOESN'T WORK

          SetAlarmForPerson-DDW.txt("main","")

          sub main(Nulldata)
          SetAlarmFor code here
          end sub
          sub AlarmSetFor(Nulldata)
          ...
          end sub
          --DOESN'T WORK

          SetAlarmForPerson-DDW.txt("SetAlarmFor")

          sub main()
          ' No code
          end sub
          sub SetAlarmFor()
          ...
          end sub
          sub AlarmSetFor()
          ...
          end sub
          --DOESN'T WORK


          The only variation that works is the one that doesn't send any parameters to the script...

          Comment


            #6
            Copy and paste the following code into a file named MySubTest.txt (or download the attached file) and drop it into your HomeSeer\scripts directory.

            <pre class="ip-ubbcode-code-pre">
            sub main()

            end sub

            sub MySub1()
            msgbox "Hello from MySub1"
            end sub

            sub MySub2(mystring)
            msgbox "Hello from MySub2. The param you passed in was -- " & mystring
            end sub

            </pre>

            If you enter MySubTest.txt("mysub1") for the event and then press test, a message box pop up and it will say "Hello from Sub 1"

            Change it to MySubTest.txt("mysub2") and then press test and a message box will pop up and it will say "Hello from MySub2. The param you passed in was -- "

            Change it to MySubTest.txt("mysub2","Yo Sub2!") and then press test and a message box will pop up and it will say "Hello from MySub2. The param you passed in was – Yo Sub2!"

            Hope this helps.

            Joe
            HomeSeer Rocks!

            [This message was edited by Joe's Place on Thu, 19 February 2004 at 11:22 PM.]
            Attached Files

            Comment


              #7
              The subroutines are called just fine, the problem is the Voice Recognition through the Hi-Phone USB device doesn't work properly.

              The tests you propose will work fine. The problems would arise if we added a Voice Recognition routine to the subroutines.

              The following code runs just fine if it's in the "sub main()" and is called without passing any parameters. Even "sub main(Nulldata)" called with:
              SetAlarmForPerson-DDW.txt("main", "")
              will "break" the VR routine.

              The way the following code works is it prompts you with:
              "Confirm with yes"
              and then wait until you say either "yes", "no" or "cancel" (or until 15 seconds pass with no voice command)

              When called with passed parameters, the script acts as though it has finished without waiting for a VR command. It gives my HSPhone prompt "Yes?" and recognizes only the standard HSPhone commands (such as Goodbye, or Messages) and not my specified "yes", "no", and "cancel". The script is actually still running because My test line "Exiting voice command loop--&gt;..." hasn't been logged yet. I can say "goodbye" or "messages" and those will be recognized even though it's still in my script.

              Again, this happens only when a parameter is passed to the script, not if the VR is in main() and called without passing parameters.

              Voice Recognition Code Example:

              system.ClearAllVoiceCommands

              system.AddVoiceCommand "yes"
              system.AddVoiceCommand "no"
              system.AddVoiceCommand "cancel"
              system.speak "Confirm with yes.", TRUE
              system.LastVoiceCommand=""
              system.startlisten
              timeout = timer + 15

              hs.writelog "TEST", "Entering voice command loop"
              do
              cmd=system.LastVoiceCommand
              if Timer &gt; Timeout then cmd="timeout"
              if cmd &lt;&gt; "" then exit do
              hs.waitevents
              loop
              hs.writelog "TEST", "Exiting voice command loop--&gt;" & cmd
              system.stoplisten

              Select Case cmd
              Case "yes"
              ....

              system.ClearAllVoiceCommands

              Rich or Rick, any ideas??

              Thanks,
              Doug

              Comment


                #8
                This Bit me AGAIN!!!

                I just spent about two hours troubleshooting another VR routine, when I finally remembered this bug.

                I just completely rebuilt my Homeseer system, so it is NOT a hardware issue.

                Anyone?? (See my post above...)

                Sorry, it's late and I could have had my program done if I hadn't been chasing this.

                Doug W.

                Comment


                  #9
                  You need to open an HST Help Desk ticket/bug report on their web site - you may not get a response here.
                  |
                  | - Gordon

                  "I'm a Man, but I can change, if I have to, I guess." - Man's Prayer, Possum Lodge, The Red Green Show
                  HiddenGemStudio.com - MaineMusicians.org - CunninghamCreativeMaine.website

                  Comment


                    #10
                    This problem is fixed in HSP 2.0.186 which is in the updater.

                    The problem was that HSP was checking the event to see if it was attempting to run multiple scripts like "s1.txt,s2.txt". It cannot handle this, you can only run one script from an event if its launched by a VR command on the phone so it would log an error message for this case. However, when you attempt to run a script with parameters there is a comma in the launch info, which fooled HSP. I have simply removed this check so scripts with parameters run ok. Just be aware that you cannot launch multiple scripts from an HSP VR command. Probably not a problem anyone would see.
                    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                    Comment


                      #11
                      Thanks for the fix and the explaination. I'll give the update a try in the next couple of days.

                      Thanks again!
                      -Doug W.

                      Comment

                      Working...
                      X