Author Topic: Stopwatch with readback  (Read 3751 times)

Irolan

  • Guest
Stopwatch with readback
« on: July 10, 2017, 03:17:17 PM »
Hello,

I'm working on a stopwach that is supposed to run in the background. Main feature is that VA is supposed to read back the current time to me when I ask for it. However, the timer is running approximately 2-3 times faster than it actually should.

I have three small integers, called hours, minutes and seconds. They are incremented in a continuously running command which looks like this:

Code: [Select]
Begin Small Integer Compare : [seconds] Is Less Than 60
     Set small int (condition) [seconds] value as incremented by 1
Else
     Set Small int (condition) [seconds] value to 0
     Begin Small Integer Compare : [minutes] Is Less Than 60
          Set small int (condition) [minutes] value as incremented by 1
     Else
          Set small int (condition) [minutes] to 0
          Set small int (condition) [hours] value as incremented by 1
     End Condition
End Condition
Pause 1 second

This command is set to "This command repeats continuously". It looks like "Pause 1 second" is not very reliable.
Is there any better way to do this? Also, I'm looking for a way to have it read back the current time to me. I cannot use "Say something with text-to-speech" with the {time} token because I'm using a pre-recorded voice.

Any help would be greatly appreciated.
« Last Edit: July 10, 2017, 03:30:31 PM by Irolan »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Stopwatch with readback
« Reply #1 on: July 10, 2017, 04:24:56 PM »
There's an advanced example in this topic.

Regardless of features, there's no need to manually keep track of time, the hardware clock in your computer already does that for you.

Here's a basic example(functionality wise):
Stopwatch start
Code: [Select]
Set decimal [startTime] value to the converted value of {DATETICKS}

Stopwatch interval
Code: [Select]
Set decimal [intervaltoprocess] value to the converted value of {EXP: {DATETICKS} - {DEC:startTime}}
Inline C# Function: Ticks to Human Readable Time, wait until execution finishes
Write '[Blue] Time elapsed: {INT:intervalHours}:{INT:intervalMinutes}:{INT:intervalSeconds}' to log

Where "Ticks to Human Readable Time" contains:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
TimeSpan interval = TimeSpan.FromTicks(Convert.ToInt64(VA.GetDecimal("intervaltoprocess")));
                VA.SetInt("intervalHours", interval.Hours);
                VA.SetInt("intervalMinutes", interval.Minutes);
                VA.SetInt("intervalSeconds", interval.Seconds);
}
}

The inline function means you don't have to reinvent the wheel to get back from ticks to human readable time.

I'm using regular integers to both save on casting them, and because Gary has considered getting rid of small integers at some point in the future(with backwards compatibility intact no doubt, but better to start early I figure).


One big benefit of using a static starting point is that there's nothing running in the background to keep track of time(that isn't always running when your computer's plugged in), and if you save the value somewhere, you can shut down your computer entirely, and you can still get the elapsed time from that value.

To "reset" the stopwatch, all you need to do is use "Stopwatch start" again to change the starting point.

Irolan

  • Guest
Re: Stopwatch with readback
« Reply #2 on: July 10, 2017, 05:39:56 PM »
Hello Pfeil,

first of all, thanks for your answer. Those code blocks, are those separate commands or should they be put in the same command? Also, how do I use code? I can't find that.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Stopwatch with readback
« Reply #3 on: July 10, 2017, 06:07:16 PM »
The "code" blocks are what you would see in the action list within VoiceAttack. They generally offer enough information to recreate commands, but it has to be done manually.

I've exported the commands so you don't have to do that. They're attached to this post.

Irolan

  • Guest
Re: Stopwatch with readback
« Reply #4 on: July 10, 2017, 11:11:19 PM »
Thanks a lot Pfeil. I'll check it out.

Edit:
Yes, it works! I also found where I can enter code. My version of Voiceattack was actually so old it didn't have that yet. Thank you very much, Pfeil!

Now I'll need to find out how I can make it tell me the current time.
« Last Edit: July 11, 2017, 12:28:06 PM by Irolan »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Stopwatch with readback
« Reply #5 on: July 12, 2017, 10:23:50 AM »
Current time can be separated into hours, minutes, and seconds, by using the appropriate tokens:
Quote
{TIME} - The current time, expressed in a 24-hour clock.
{time} - The current time, expressed as a 12-hour clock.
{TIMEHOUR} - The hour of the current time, expressed in a 12-hour clock.
{TIMEHOUR24} - The hour of the current time, expressed in a 24-hour clock.
{TIMEMINUTE} - The minute of the current time.
{TIMESECOND} - The second of the current time.
{TIMEAMPM} - The AM/PM designation of the current time (or the proper designation of AM/PM in the set culture).

If you have prerecorded samples for each element, you could use those tokens as part of the file name:
Code: [Select]
Play sound, '{VA_SOUNDS}\ClockHour{TIMEHOUR24}.mp3'  (and wait until it completes)
Play sound, '{VA_SOUNDS}\ClockMinute{TIMEMINUTE}.mp3'  (and wait until it completes)
Play sound, '{VA_SOUNDS}\ClockSecond{TIMESECOND}.mp3'  (and wait until it completes)

E.G. if it's 15:03:06, the files "ClockHour15.mp3", "ClockMinute03", and "ClockSecond06", would be played in sequence.