| SexScripts : Check when a script was last run - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=321 | Page 1 of 1 |
Check when a script was last run |
Banjo [ Thu Jul 04, 2013 2:32 pm ] |
|---|---|
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. |
|
Re: Check when a script was last run |
doti [ Sat Jul 06, 2013 10:58 am ] |
|---|---|
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 |
|
Re: Check when a script was last run |
Banjo [ Sat Jul 06, 2013 3:01 pm ] |
|---|---|
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? |
|
Re: Check when a script was last run |
doti [ Sun Jul 07, 2013 9:34 am ] |
|---|---|
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) //.... |
|
Re: Check when a script was last run |
asdf1234 [ Tue Nov 12, 2013 1:03 pm ] |
|---|---|
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. |
|
Re: Check when a script was last run |
doti [ Tue Nov 12, 2013 8:43 pm ] |
|---|---|
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") //.... |
|
Re: Check when a script was last run |
asdf1234 [ Wed Nov 13, 2013 8:17 am ] |
|---|---|
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! |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |