United Kingdom
Asked — Edited

Speaking The Time

@Rich.

I was looking through the forum and came across a thread where you mentioned you made a script to speak the current time. I tried it out but I'm having a problem with it. When I start the script, it only says "The time is dollar the time". Is there something that I need to change in the syntax as I know this posted a year ago and something might have changed.


IF ($hour>12)
  $hour_word=$hour-12
ELSE 
  $hour_word=$hour
ENDIF 
  
IF ($hour_word=0)
  $hour_word=12
ENDIF 
  
IF ($Minute = 0)
  $thetime = "$hour_word"
ELSEIF ($minute = 1)
  $thetime = "one minute past $hour_word"
ELSEIF ($minute = 15)
  $thetime = "quarter past $hour_word"
ELSEIF ($minute = 30)
  $thetime = "half past $hour_word"
ELSEIF ($minute  30)
  $hour_word=$hour_word+1
  $minute_word = 60-$minute
  $thetime = "$minute_word minutes to $hour_word"
ELSE 
  $thetime = "$hour_word $minute"
ENDIF 
  
IF ($hour 21)
  $thetime = "$thetime at night"
ELSEIF ($hour > 17)
  $thetime = "$thetime in the evening"
ELSEIF ($hour > 11)
  $thetime = "$thetime in the afternoon"
ENDIF 
  
Say("The time is $thetime")

Many thanks.


ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#9  

LOL.... @Rich must of been pulling an all nighter when he wrote that code.... It's probably not his anyway.... I know, Melvin probably wrote it while Rich was in the shower....:P

United Kingdom
#10  

That would explain it :D. I just posted an edit in post #8.

Thanks again.

United Kingdom
#11  

Got rid of the speech saying "Hours" "Minutes" and changed "Afternoon" to "PM".

Cheers for doing that for me Richard. ;)

United Kingdom
#13  

I haven't read the whole topic as I don't have time right now but always check the syntax on older projects. The syntax was changed a while back but any scripts from before the change may not work as desired.

I did spot @Richard mention the variable needs to be outside of the quotes, which is correct, but it also need a little more to it (which may have been done but like I said, I didn't have time to read it all).

Correct syntax for speaking a sentence including a variable is...

SayWait("The time is " + $hour + $minute)

Note the addition of the + in the code.

Also, I've probably got a much better script now than back then. Time is a tricky one for speaking since we don't say "It's 11:55" we say "It's 5 to 12" or we don't say "It's 7:05" we say "it's 5 past 7" (amongst other variations).

I'll see what other scripts I have floating around in my projects once I've had some sleep:)

United Kingdom
#14  

Hi Rich. I heed your words about checking syntax on old scripts. As I only started using ARC a few months ago, I must admit that it didn't initially think about any code or script changes or improvements at first, but suspected that might be the case after looking through other forum threads. With Richards help, here's what I'm using now...


IF ($hour>12)
$hour_word=$hour-12
ELSE
$hour_word=$hour
ENDIF
IF ($hour_word=0)
$hour_word=12
ENDIF
IF ($Minute = 0)
$thetime = $hour_word
ELSEIF ($minute = 1)
$thetime = "one minute past "+$hour_word
ELSEIF ($minute = 15)
$thetime = "quarter past "+$hour_word
ELSEIF ($minute = 30)
$thetime = "half past "+$hour_word
ELSEIF ($minute =30)
$hour_word=$hour_word+1
$minute_word = 60-$minute
$thetime = $minute_word+" minutes to "+$hour_word
ELSE
$thetime = $hour_word+" "+$minute+ " "
ENDIF
IF ($hour >21) 
$thetime = $thetime+" AM"
ELSEIF ($hour > 17)
$thetime = $thetime+" PM"
ELSEIF ($hour > 11)
$thetime = $thetime+" PM"
ELSE
$thetime = $thetime+" AM"
ENDIF

Say("The time is "+$thetime)

It works very well but I do agree with what you say about how we speak the time, but I am happy with this for now. :)

United Kingdom
#15  

My original project will be re-written with improvements for the time phrases shortly.

Time phrase updates will include: It is $hour o clock in the $timeofday It is $minute minutes past $hour in the $timeofday It is quarter past $hour in the $timeofday It is half past $hour in the $timeofday It is $minutesto to $hour+1 in the $timeofday It is quarter to $hour+1 in the $timeofday It is $minutes past $hour in the $timeofday It is $hour $minutes in the $timeofday

It shouldn't be too difficult to write for these phrases. I'll probably do another speak the "rounded" time where it'll round to 5 or 10 minute intervals (just as we do) with "almost", "around and "just gone".

I needed something to get my teeth stuck in to just to keep me sharp, this should be a good start:)

United Kingdom
#16  

Yeah I know the feeling. Anyway that would be great. I look forward to see what you'll come up with. ;)