Author Topic: Make a countdown timer?  (Read 5605 times)

bmwflyboy

  • Guest
Make a countdown timer?
« on: December 05, 2016, 05:18:39 AM »
I would like to have voice attack say how many days are left till a certain date. Is there anyone out there that could help me figure out the code for this? I would like to say "Jarvis, how many days till my birthday?" and then the computer would calculate how many days between today and my birthday and say "There are X days until your birthday."

I can get it to do easier things like " What time is it? " and the computer will tell me. Same thing with the date.

Anyone know how to do this?

Thanks.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Make a countdown timer?
« Reply #1 on: December 05, 2016, 08:59:23 AM »
Try this:
Code: [Select]
Set date [TargetDate] value to 13/07/2017 16:44:49
Set integer [DaysToTarget] value to the converted value of {EXP: ({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}
Say, 'Your birthday is in {INT:DaysToTarget} days'
I'm using the integer to lop off the fractional part of the calculation, and leave you with whole days.

bmwflyboy

  • Guest
Re: Make a countdown timer?
« Reply #2 on: December 05, 2016, 10:46:26 AM »
Thank you for helping me. I have been able to do a few things with Arduino's but not a whole lot. People like you help keep me going on how to figure things out. I like the code you put up. I see the logic in it. I can't get it to work though. It says to me " Your birthday is in not set days".  I attached a screen shot of what I have and I also copied and pasted the integer line to make sure it was exactly what you wrote. Also in the Voice Attack Log it says : Integer token could not be converted : {EXP: ({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}

Any ideas?
« Last Edit: December 05, 2016, 10:59:08 AM by bmwflyboy »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4747
  • RTFM
Re: Make a countdown timer?
« Reply #3 on: December 05, 2016, 12:18:50 PM »
For the integer trick to work, you need beta v1.6.1.1 or higher, otherwise it will indeed not convert it, and not set the integer.

Alternatively, we can treat the value as a string and simply use only the part we want:
Code: [Select]
Set date [TargetDate] value to 13/07/2017 16:44:49
Set integer [DaysToTarget] value to the converted value of {TXTSUBSTR:"{EXP:({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}":0:{TXTPOS:".":"{EXP:({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}":"0"}}
Say, 'Your birthday is in {INT:DaysToTarget} days'
That sequence of tokens will select from the start of the value to the decimal point, so the fractional part is cut off.

The advantage is that this will work with v1.6, provided the "Use Nested Tokens" option is checked(which it is by default).

bmwflyboy

  • Guest
Re: Make a countdown timer?
« Reply #4 on: December 05, 2016, 01:49:24 PM »
Thank you! That worked perfectly.

bmwflyboy

  • Guest
Re: Make a countdown timer?
« Reply #5 on: December 06, 2016, 01:54:28 PM »
So I am not sure what is going on now. I took my computer over to a friend to show him my counter and of course when I try and show it off it doesn't work. I am now getting this error message and I don't know why or what changed.

Integer token could not be converted : {TXTSUBSTR:"{EXP:({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}":0:{TXTPOS:".":"{EXP:({DATETICKS:TargetDate} - {DATETICKS}) / 864000000000}":"0"}}

If you have any other suggestions on how to fix this I'd be grateful.

Some things have changed though: I have uninstalled and reinstalled the program, reset program defaults and also tried an experimental executable from Gary for things not related to this. So the problem could be anywhere.

Aaand...I fixed it. I turned on Nested tokens in the settings menu.
« Last Edit: December 06, 2016, 02:01:27 PM by bmwflyboy »