de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Wait until HH:mm?
PostPosted: Tue Nov 01, 2016 10:56 pm 
Offline
Regular
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?


Top
 Profile Send private message 
 
 Re: Wait until HH:mm?
PostPosted: Thu Nov 03, 2016 7:30 pm 
Offline
Site Admin
User avatar
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)
   }
}


Top
 Profile Send private message 
 
 Re: Wait until HH:mm?
PostPosted: Fri Nov 04, 2016 12:24 am 
Offline
Regular
That's cool!

Thank you! :)


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.