I want the script to wait until a predetermined time in HH:mm format is reached.
wait() just accepts seconds.
But it would be inconvenient to ask the slave 'in how many seconds will you be back?'
So i scripted this:
Code:
String strInput
String[] partInput
String[] partTime
def timeNow
def timeInput
def WaitSeconds
def WellDone = false
//Loop until slave used correct input
while (!WellDone)
{
//get actual time as HH:mm
timeNow = new Date().format("HH:mm")
//Split string and convert to seconds
partTime =timeNow.split(':')
partTime[0] = partTime[0].toInteger() * 3600
partTime[1] = partTime[1].toInteger() * 60
timeNow = partTime[0] + partTime[1]
timeNow = timeNow.toInteger()
// Ask slave for future time (must be same day)
strInput = getString("When can you be back?", "HH:mm" )
//Check if':' is contained and length == 5
WellDone = strInput.contains(":") && strInput.length() == 5
if(WellDone == true)
{
partInput =strInput.split(':')
partInput[0] = partInput[0].toInteger() * 3600
partInput[1] = partInput[1].toInteger() * 60
//Get seconds between now and slaves future time
timeInput = partInput[0] + partInput[1]
timeInput = timeInput.toInteger()
WaitSeconds = timeInput - timeNow
show(WaitSeconds)
}
else
{
show("Fool! Write the time properly!\nLike 14:30 for example!")
wait(2)
}
}
I do not deny that i learned a lot about groovy scripting (I am a beginner in this, though not unexperienced in other program languages), but i am asking myself (and you, of course) if there is a better approach?
Didn't i see the forest for the trees?