Author Topic: Countdown timer while waiting for command  (Read 2046 times)

Coret

  • Guest
Countdown timer while waiting for command
« on: November 03, 2018, 01:47:13 PM »
Hello,

I am trying get VA ready to execute a command when I say "mark". I know of the option "wait for spoken response", but the issue that I have with that option is that it doesn't give any feedback on the time remaining. So I created an alternative that it works as follows:

Say, 'Understood.'
Set Boolean [mark] to False
Set integer [time] value to 0
Pause 0.95 seconds
Start Loop While : [mark] Equals False
    Begin Integer Compare : [time] Is Less Than 29
        Set integer [time] to [time] plus 1
    Else
        Say, 'No command acknowledged.'
        Exit Command
    End Condition
    Begin Integer Compare : [time] Equals 20
        Say, '10 seconds left'
    End Condition
    Begin Integer Compare : [time] Equals 25
        Say, '5'
    End Condition
    Begin Integer Compare : [time] Equals 26
        Say, '4'
    End Condition
    Begin Integer Compare : [time] Equals 27
        Say, '3'
    End Condition
    Begin Integer Compare : [time] Equals 28
        Say, '2'
    End Condition
    Begin Integer Compare : [time] Equals 29
        Say, '1'
    End Condition
    Pause 1 second
End Loop
Press C key and hold for 0.1 seconds and release
Say, 'Command accepted.'

And I created the command "mark" with sets the Boolean of the same name to true.

Although this works, it can take 1 second for the command to be executed due to the pause of one second at the end of the loop. Does anyone knows if there is a more elegant approach to this?

Regards

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Countdown timer while waiting for command
« Reply #1 on: November 03, 2018, 03:13:34 PM »
I don't know about elegant, but this will respond to "mark" being true immediately:

Code: [Select]
Say, 'Understood.'
Set Boolean [mark] to False
Set integer [~currentWait] value to 20
Set date [~startTime] to [~startTime] plus [20] seconds
Start Loop While : [mark] Equals False
    Begin Date Compare : [~startTime] Is Less Than Or Equals Current Date/Time
        Begin Integer Compare : [~currentWait] Equals 20
            Set integer [~currentWait] value to 10
            Set date [~startTime] to [~startTime] plus [5] seconds
        Else If Integer Compare : [~currentWait] Equals 10
            Say, '10 seconds left'
            Set integer [~currentWait] value to 5
            Set date [~startTime] to [~startTime] plus [1] seconds
        Else If : ([~currentWait] Is Less Than Or Equals 5 AND [~currentWait] Is Greater Than 0)
            Say, '{INT:~currentWait}'
            Set integer [~currentWait] to [~currentWait] minus 1
            Set date [~startTime] to [~startTime] plus [1] seconds
        Else
            Say, 'No command acknowledged.'
            Exit Command
        End Condition
    End Condition
End Loop
Say, 'Command accepted.'

Coret

  • Guest
Re: Countdown timer while waiting for command
« Reply #2 on: November 05, 2018, 08:38:10 PM »
Hello Pfeil,

Wow, I had no idea that was possible! So from my understanding the variable ~startTime will always get the current machine time right?

Took me awhile to understand it, but once I did I made a few modifications. Bumped the "say 10 seconds left" to the first integer compare and end up removing that middle compare.

Code: [Select]
Say, 'Understood.'
Set Boolean [mark] to False
Set integer [~currentWait] value to 20
Set date [~startTime] to [~startTime] plus [20] seconds
Start Loop While : [mark] Equals False
    Begin Date Compare : [~startTime] Is Less Than Or Equals Current Date/Time
        Begin Integer Compare : [~currentWait] Equals 20
            Set integer [~currentWait] value to 5
            Set date [~startTime] to [~startTime] plus [5] seconds
            Say, '10 seconds [left' or 'remaining]'
        Else If : ([~currentWait] Is Less Than Or Equals 5 AND [~currentWait] Is Greater Than 0)
            Say, '{INT:~currentWait}'
            Set integer [~currentWait] to [~currentWait] minus 1
            Set date [~startTime] to [~startTime] plus [1] seconds
        Else
            Say, 'No command acknowledged'
            Exit Command
        End Condition
    End Condition
End Loop
Say, 'Command accepted'
Press C key and hold for 0.1 seconds and release

Thanks for the help!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Countdown timer while waiting for command
« Reply #3 on: November 05, 2018, 10:16:55 PM »
Wow, I had no idea that was possible! So from my understanding the variable ~startTime will always get the current machine time right?
Just so we're clear: The name of the variable is irrelevant, but yes, using the "Set a Date/Time Value" action in this manner will get the current time if it has not been set yet(which it won't be when the command starts because it's a local variable, as denoted by the "~" prefix).

I made a few modifications. Bumped the "say 10 seconds left" to the first integer compare and end up removing that middle compare.
That'd be the way to do it. I should've picked up on that; Too many irons in the fire I guess.