Need help with some sort of time elapsed checker

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Haduis
Newbie
Posts: 5
Joined: Wed Oct 16, 2013 5:23 am

Need help with some sort of time elapsed checker

Post by Haduis » Wed Oct 16, 2013 5:37 am

Script needs to logically work like the following pseudo-script

GetTime

Label>First

..Do some stuff...


if>8 minutes have passed, (True) goto Second, (False) goto first

Label>Second

..Do some stuff...

Reset time to new current time


In words, I need it to keep doing first until 8 minutes have passed, then go to Second, then repeat

Any simple way to do this that doesn't rely on adding to a counter?

User avatar
Grovkillen
Automation Wizard
Posts: 1132
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Post by Grovkillen » Wed Oct 16, 2013 6:28 am

Hello,

Here's my take at the problem...

Code: Select all

Let>MIN_TIME_BETWEEN_DO_THINGS=8
//Size could be H(hours), M(minutes) or S(seconds)
Let>TIME_SIZE=M

//Fix MIN_TIME_BETWEEN_DO_THINGS to get the IF statement ">="
Let>CHECK_TIME=MIN_TIME_BETWEEN_DO_THINGS-1

Label>START_ALL_OVER
GetTime>TIME1
Label>DO_THING_1_ONCE_AGAIN
GetTime>TIME2
TimeDiff>%TIME1%,%TIME2%,%TIME_SIZE%,TIME_DIFF
If>TIME_DIFF>CHECK_TIME
    GoSub>DO_THING_2
    Goto>START_ALL_OVER
Else>
    GoSub>DO_THING_1
    Goto>DO_THING_1_ONCE_AGAIN
Endif>

SRT>DO_THING_1
  //Do your stuff here
END>DO_THING_1

SRT>DO_THING_2
  //Do your other stuff here
END>DO_THING_2
PS. I'm not sure but I think it would be easier if I could use ">=" (greater or equal to) and thus not have to manipulate the wanted wait time (i.e. not make a new variable that is -1 of the wanted wait time. In my example I call this new variable CHECK_TIME). Please have a look at this request that has not been added yet>>.

EDIT: I read through the request and found out that you CAN make the "greater or equal to" work by using {}. Edited code below:

Code: Select all

//Global variables
Let>MIN_TIME_BETWEEN_DO_THINGS=8
//Size could be H(hours), M(minutes) or S(seconds)
Let>TIME_SIZE=S

Label>START_ALL_OVER
GetTime>TIME1
Label>DO_THING_1_ONCE_AGAIN
GetTime>TIME2
TimeDiff>%TIME1%,%TIME2%,%TIME_SIZE%,TIME_DIFF
If>{%TIME_DIFF%>=%MIN_TIME_BETWEEN_DO_THINGS%}
    GoSub>DO_THING_2
    Goto>START_ALL_OVER
Else>
    GoSub>DO_THING_1
    Goto>DO_THING_1_ONCE_AGAIN
Endif>

SRT>DO_THING_1
  //Do your stuff here
  Message>Doing thing 1%CRLF%%CRLF%Time elapsed: %TIME_DIFF% %TIME_SIZE%
  //Just to slow the example down...
  Wait>1
END>DO_THING_1

SRT>DO_THING_2
  //Do your other stuff here
  MessageModal>Doing thing 2!%CRLF%%CRLF%Time elapsed: %TIME_DIFF% %TIME_SIZE%
  //Exit>0
END>DO_THING_2
Let>ME=%Script%

Running: 15.0.27
version history

Haduis
Newbie
Posts: 5
Joined: Wed Oct 16, 2013 5:23 am

Post by Haduis » Wed Oct 16, 2013 7:12 am

While waiting for a response I came up with this, any inherent flaws? What if it counts into the millions or billions?

Both are meant to be tested in notepad, if you're interested. It waits 2 seconds for you to tab into notepad before going

Code: Select all


Let>SecsAdd=5000
Wait>2

Label>First
Timer>Time

Send>Doing stuff one
Wait>.5

If>%Time%>%SecsAdd%,Second,First

Label>Second

Send>Doing second stuff
Wait>.5

Let>SecsAdd=SecsAdd+5000
goto>First


More complex version incorporating three "Doing things", with two on separate timers and one that goes until the others take their turn

Code: Select all




Let>SecsAdd1=5000
Let>secsAdd2=8000
Wait>2

Label>Stuff1
Send>Doing stuff
Press Enter
Wait>.5

Label>Timer1
Timer>time
If>%Time%>%SecsAdd1%,Stuff2,Timer2

Label>Timer2
Timer>time
If>%time%>%SecsAdd2%,Stuff3,Stuff1

Label>Stuff2
Send>Doing second stuff
Wait>.5
Press Enter
Let>SecsAdd1=SecsAdd1+5000
goto>Timer2

Label>Stuff3
Send>Doing Third stuff
Press Enter
Wait>.5
Let>SecsAdd2=SecsAdd2+8000
goto>Stuff1

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts