SexScripts : Wait until HH:mm? - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=656 Page 1 of 1

Wait until HH:mm?

Eddy [ Tue Nov 01, 2016 10:56 pm ]

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?

Re: Wait until HH:mm?

doti [ Thu Nov 03, 2016 7:30 pm ]

Looks good.

Perhaps using exception will cover more user input errors :
Code:
String strInput
String[] partInput
String[] partTime
def timeNow
def timeInput
def WaitSeconds
def WellDone = false

//Loop until slave used correct input
while (!WellDone)
{
   try
   {
      //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" )
      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)
      WellDone = true
   }
   catch(any)
   {
      show("Fool! Write the time properly!\nLike 14:30 for example!")
      wait(2)
   }
}

Re: Wait until HH:mm?

Eddy [ Fri Nov 04, 2016 12:24 am ]

That's cool!

Thank you! :)

Page 1 of 1 All times are UTC + 1 hour [ DST ]
https://ss.deviatenow.com:443/
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010, 2011