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

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

#1  

You made a mistake on the last line... You put the variable in quotes... Say("The time is $thetime") should be Say("The time is "+$thetime)

You can also use the reserved variable for time.... which is $time... There is also $hour, $minute...etc... these variables can be found at the end if the script function list in every script...


#quick and dirty code
Say("The time is "+$time)

Variable Constants/Reserved Words These variables are read-only reserved words and cannot be assigned. $direction $date $month $year $day $dayName $hour $minute $second $monthName $time $pi

#2  

... Oh man, who wrote this it's a mess? I know for sure @Rich didn't...LOL...Way more corrections... variables shouldn't be in quotes and some operator signs were missing... There still may need more corrections...



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) #I assume it is greater than as the sign was left out in the code
  $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)

#3  

@Steve.... Tried to run my version, but it doesn't work well at all.... I think this has to be completely re-written my friend... I could fix it, but I won't have anytime today... Sorry dude

United Kingdom
#4  

@Richard.

Not a problem mate. I copied this code straight from Rich's example and was curious if there was a new way to write this, as his example is over a year old. If you wouldn't mind haveing a look when you have some free time I would appreciate it. In the meantime I will have a play around too (but I don't hold much hope with my current scripting skills eyeroll).

#5  

@Steve... can you show me the link to it? No promises, but I will see what I can do...

#6  

Try this... It may still need more tweaking.... make sure you copy it exactly as it is below...


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+" hours and "+$minute+" minutes"
ENDIF 
 IF ($hour >21) #I assume it is greater than as the sign was left out in the code
  $thetime = $thetime+" at night"
ELSEIF ($hour > 17)
  $thetime = $thetime+" in the evening"
ELSEIF ($hour > 11)
  $thetime = $thetime+" in the afternoon"
ELSE
  $thetime = $thetime+" in the morning"
ENDIF 
  
Say("The time is "+$thetime)

United Kingdom
#7  

Sure. The link for Rich's project is hear at the end of post #6.

EDIT:

I just tried your code Richard and it works pretty well.

"The time is 12 hours and 51 minutes in the afternoon."

I'd like the lose the "hours" "minutes" and change "afternoon" for "PM" if poss, but hey, it works. Thanks buddy. :)