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


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Check when a script was last run
PostPosted: Thu Jul 04, 2013 2:32 pm 
Offline
Veteran
User avatar
I'm sure I figured this out once before but couldn't find the topic here again. :(

Can someone either point me to a thread showing how, or let me know briefly how to do the following:

Set a global value as to when a script is run (or when something happens in a script), then when it's run again, check to see if X amount of time (say, 1 hour or 1 day) has passed since the previous value was set (or the script was run) so that an if...else can be used.

I presume this means using getTime but my attempts so far setting a timestamp and then comparing it have failed. :(


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Sat Jul 06, 2013 10:58 am 
Offline
Site Admin
User avatar
Hi

You could use this :
Code:
def lastTime = loadInteger("script1.launch.lasttime")
def lapse = 0
if(lastTime!=null)
   lapse = getTime() - lastTime
...
show(lapse)  //seconds


But it won't work, as this automatic variable, "script1.launch.lasttime", is updated at the very beginning of the script. So you'll need to do this instead ("beforetime" is not a special name) :
Code:
//start
def beforeTime = loadInteger("script1.launch.beforetime")
def lapse = 0
if(beforeTime!=null)
   lapse = getTime() - beforeTime
save("script1.launch.beforetime", getTime())

//.....

show(lapse)

//....


here is the main thread about dates


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Sat Jul 06, 2013 3:01 pm 
Offline
Veteran
User avatar
Hi!

That works great for general "how long since this script was last run". Thanks!

But how about if I wanted to check when the last time a specific action was taken (i.e. a particular variable was set)?

For example, if the user chooses "yes" to a yes or no question, the script makes a timestamp. When the script is re-run, it will tell the user: "you last answered yes X seconds ago". If they click "yes" another time, the timer resets to the current timestamp. If they click "no", the timer does not reset (previous timestamp is kept). Does that make sense?

In short, is there a way to do the above in your previous post but NOT have it "reset" every time the script is run unless told specifically to?


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Sun Jul 07, 2013 9:34 am 
Offline
Site Admin
User avatar
Yes, only the line with "save" saves the new value. Here is a solution :
Code:
//start
def beforeTime = loadInteger("script1.somethingHappened")
def lapse = 0
if(beforeTime!=null) //if it exists (if not, value will be 0)
   lapse = getTime() - beforeTime

if(....) { //only saves sometimes
  save("script1.somethingHappened", getTime())
}

//.....

show(lapse)

//....


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Tue Nov 12, 2013 1:03 pm 
Offline
Regular
User avatar
On this topic, what would be the value of lapse after 1 hour, 1 day, and 1 week? I tried it almost immediately after and the value I was given was '157' or something along those lines. Is there some way to work out how long a specific duration is, so that I could say 'If lapse > (value for a day) then do this'? I realise there may be a better way to do that particular example, but it's just one example of the many uses I will have for this.


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Tue Nov 12, 2013 8:43 pm 
Offline
Site Admin
User avatar
It should be in seconds.

For 1 hour, 1 day, 1 week, it'll be this
Code:
//start
def beforeTime = loadInteger("script1.somethingHappened")
def lapse = 0
if(beforeTime!=null) //if it exists (if not, value will be 0)
   lapse = getTime() - beforeTime
if(....) { //only saves sometimes
  save("script1.somethingHappened", getTime())
}

//.....

if(lapse>60*60) show("at least one hour")
if(lapse>60*60*24) show("at least one day")
if(lapse>60*60*24*7) show("at least one week")

//....


Top
 Profile Send private message 
 
 Re: Check when a script was last run
PostPosted: Wed Nov 13, 2013 8:17 am 
Offline
Regular
User avatar
Thanks Doti - figured that out shortly after. The way I had it written in the value was some way changing, so I rewrote that part of it and now it works great!


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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.