Asked — Edited

Script For Robot'S Age

I know this topic came up once or twice before to script a method so your robot could know it's age. I first scripted a process in PowerShell to come up with the exact age from a given birthday for your robot, but I wanted to script it in ARC and I didn't want to make a plug in (I know that idea got tossed around before). I just wanted something simple.

This is my script, it lets your robot say it's approximate age. Just wanted to get opinions on it. Does anyone see something they might do differently?


$UseEZBSpeaker = false
#Print($day)
#Print($month)
#Print($year)

#enter your robot's birthday below
$AIBirthDay = 12 
$AIBirthMonth = 6
$AIBirthYear = 2015

$szAgeYears = ($year - $AIBirthYear) 
$szAgeMonths = ($month - $AIBirthMonth)
$szAgeDays = ($day - $AIBirthDay)
#Print($szAgeYears)
#Print($szAgeMonths)
#Print($szAgeDays) 

if ($szAgeYears  1)
Print("I am less than 1 year old. I am about " + $szAgeMonths + " months old.")
$szToSay = "I am less than 1 year old. I am about " + $szAgeMonths + " months old." 
endif

if ($szAgeYears  1)
Print("I am less than 1 year old. I am about " + $szAgeDays + " days old.")
$szToSay = "I am less than 1 year old. I am about " + $szAgeDays + " days old."
endif 

if ($szAgeYears  1 AND $szAgeMonths > 1)
Print("I am " + $szAgeYears + " years old and " + $szAgeMonths + " months.")
$szToSay = "I am " + $szAgeYears + " years old and " + $szAgeMonths + " months."
endif 

if ($szAgeYears > 1 AND $szAgeMonths >= 1)
Print("I am " + $szAgeYears + " years old and " + $szAgeMonths + " months.")
$szToSay = "I am " + $szAgeYears + " years old and " + $szAgeMonths + " months."
endif 

if ($szAgeYears > 1 AND $szAgeMonths = 0)
Print("I am " + $szAgeYears + " years old")
$szToSay = "I am " + $szAgeYears + " years old "
endif 

if ($szAgeYears = 1 AND $szAgeMonths > 1)
Print("I am " + $szAgeYears + " year old and " + $szAgeMonths + " months.")
$szToSay = "I am " + $szAgeYears + " year old and " + $szAgeMonths + " months."
endif 

if ($szAgeYears = 1 AND $szAgeMonths = 0)
Print("I am about 1 year old.")
$szToSay = "I am about 1 year old."
endif 

if ($UseEZBSpeaker = true)
  SayEZBWait($szToSay)
ELSE
  SayWait($szToSay)
endif

$szToSay = ""


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

#1  

Maybe take these differences and calculate the number of days difference. From there you would be able to get more accurate. Leap year will affect this but you could check if the day and month are the same, it's the robots birthday and all, but with days you would be able to know if the robot is 3 months old or 9 months old for example.

#2  

Since every month has a preset number of days (other than Feb. with leap years) I suppose I could add that knowledge in the script to get a more accurate birthday. Good suggestion, thank you.

#3  

I've been using this script. I don't remember who first posted it but I didn't create it, I have modified it though.


$yearofbirth = 2013
$monthofbirth = 10
$dayofbirth = 15

$ageyear = $year - $yearofbirth
$agemonth = $month - $monthofbirth
$ageday = $day - $dayofbirth

Say(" I was first powered up on October 15, 2013, so ")

if($agemonth < 0)
  $agemonth = $agemonth + 12
  $ageyear = $ageyear - 1
endif

if($agemonth > 0)
  SayWait(" I am " + $ageyear + " years " + $agemonth + " months and " + $ageday + " days old ")

endif