United Kingdom
Asked — Edited
Resolved Resolved by Rich!

Script To Get My Robot To Say His Age

Hi guys.

I need a little help with some script. As the title says, I would like to get K-9 to say his age when somebody asks him. For example,

User. "how old are you?"

K-9. "I am 1 year, 2 months, 5 months and 2 days old."

It will obviously need a start date (Date of Birth) then have the script work out the age from that, but so far this weekend I have had a play around with a "Say the Date" script with different variations but have had no luck with it. Does anyone have a script that can be used to do this?

Thanks in advance,

Steve G.


ARC Pro

Upgrade to ARC Pro

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam ARC Pro.

United Kingdom
#1  

I'm not going to write it for you, but will give you a push in the right direction...

There are the following built in variables in ARC; $date $month $year $day

You also have the following DateTime functions available; MinDate() MaxDate() MonthName() AddDays() AddMonths() AddYears() AddHours() AddMinute() AddSeconds() FmtNum() FmtDate()

You just need to figure out how to;

  1. Set the date of birth in EZ-Script
  2. Subtract the date of birth from the current date
  3. Convert days to days, months and years
  4. Speak the result

Alternately, use PandoraBot, you can set a DOB in there and it does the calcs for you:)

#2  

@Rich.... I am sitting here staring at the ceiling trying to figure out how to do this.... LOL. I finally had an idea which was similar to yours, but since my "cpu" is a lot slower than yours you beat me to it... LOL:P

United Kingdom
#3  

Thanks for the replies guys. I have been using the $date $month $year and $day codes which the say the date script uses but no matter what I tried I just couldn't get it to work. I think the main problem is setting the date of birth. I would have posted a script to show you guys, but I changed what I had so many times I ended up deleting it in the end.:(

Thanks for the Pandorabot suggestion Rich, but I was already aware I could do it this way, but I really wanted to do this using Script's so I could learn much more about how EZ Script works and what I could do with it.

United Kingdom
#4  

Well I gave writing the "Say your age" script again this evening but to no avail. I've obviously still got a way to go with EZ Script but I'm sure I'll get there. Thanks again for the Pandorabot suggestion Rich. I think I will do it this way. As I mentioned I was aware I could do it this way but never tried it, so reluctantly I'm going to go down this route. Would like to have used EZ Script though as I enjoy using it, but I just dont have enough experience to do this just yet. confused:)

United Kingdom
#5  

If you want "I am 2 years, 11 months, 14 days, 8 hours, 27 minutes and 37 seconds old" then it's going to be long scripts.

If you wanted something as simple as "I am 7 years old" or "I am 19 months old" then it's a little easier.

For a simple yearly response;


$yearofbirth = 1980
$age = $year - $yearofbirth

SayWait("I am " + $age + " years old")

For year and month


$yearofbirth = 1980
$monthofbirth = 1

$ageyear = $year - $yearofbirth
$agemonth = $month - $monthofbirth

IF($agemonth < 0)
  $agemonth = $agemonth + 12
  $ageyear = $ageyear - 1
EndIf

If($agemonth > 0)
  SayWait("I am " + $ageyear + " years and " + $agemonth + " months old")
Else
  SayWait("I am " + $ageyear + " years old")
EndIf

With the latter you could use further ifs to force ages below 3 years to months only (as we tend to do with children).


$yearofbirth = 2012
$monthofbirth = 12

$ageyear = $year - $yearofbirth
$agemonth = $month - $monthofbirth

IF($agemonth < 0)
  $agemonth = $agemonth + 12
  $ageyear = $ageyear - 1
EndIf

If($ageyear < 3)
  $agemonth = $agemonth + $ageyear * 12
  SayWait("I am " + $agemonth + " months old")
ElseIf($agemonth > 0)
  SayWait("I am " + $ageyear + " years and " + $agemonth + " months old")
Else
  SayWait("I am " + $ageyear + " years old")
EndIf

These are just a few quick examples which I hope get you started. I haven't done one for including days, this should be pretty simple to add in if you follow what I did for the years and the months.

#6  

I'm glad you provided that example Rich, that much easier than what I was starting to do....which was to take the string of $date and parse it for the values of the month, day and year to do math against a birth date.

United Kingdom
#7  

That's how I started looking at it earlier today but I've come to learn that there is always a simpler method than how I first think.

United Kingdom
#8  

That's great. Thanks for the examples Rich. I will give them a try tomorrow. Quite different to what I initially wrote, and a lot shorter. But looking at the examples you supplied some of it is starting to make a bit more sense to me, and I can see parts where I was going wrong, especially setting the birth date, although I'm still not 100% sure I would have fully got it to work.

Thanks again for your help Rich.:)

United Kingdom
#9  

Just one more thing I want to ask to get a better understanding of how EZ Script works, like ( ) defines ports ect and " " sets speech or speech commands, what does (in laymans terms :P) the "$" sign mean, or rather what does it actually do? I think that's where I was initially having trouble.

#10  

$ tells ARC a variable is to follow. In other words this is ARC's way of identifying a variable to be used....

EDIT variable or constant I should say...