program agains relative time --- a suggestion

Asked by Bas

---- a simple solution based on seconds

waitUntilStart = time.time()
def waitUntil(nextTime):
     global waitUntilStart
     until = waitUntilStart + nextTime
     while time.time() < until:
         wait(0.1) # the granularity

waitUntilStart = time.time()
waitUntil(2.0); click();
waitUntil(2.8); click();
waitUntil(4.8); click();

---------------------------------------------------------------------

I'm using sikuli to script a tutorial; love it!

And it would be even greater to use a master time accross the program, instead of only wait commands.

so instead of

wait(1); click();
wait(0.5); click();
wait(2); click();

be able to
[start time from 0 when start to run a script]

time(0:02.00); click();
time(0:02.50); click();
time(0:04.50); click();

Is something like that possible? Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Bas
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

just an example using seconds

waitUntilStart = time.time()
def waitUntil(nextTime):
     global waitUntilStart
     until = waitUntilStart + nextTime
     while time.time() < until:
         wait(0.1) # the granularity
     waitUntilStart = time.time()

waitUntilStart = time.time()
waitUntil(2.0); click();
waitUntil(2.8); click();
waitUntil(4.8); click();

... but are you aware of the feature guide (use SikuliX version 1.1.2).
It allows some interaction, but is not well documented (you have to look into code, to get feeling about the features.

Revision history for this message
Bas (basbash) said :
#2

Thanks RainMan, I'll give this a try.
(think I have been searching for the incorrect terminology)
Have a good day!

Revision history for this message
Bas (basbash) said :
#3

With the minor tweak
If other people might use it, think there was a type-o

waitUntilStart = time.time()
def waitUntil(nextTime):
     global waitUntilStart
     until = waitUntilStart + nextTime
     while time.time() < until:
         wait(0.1) # the granularity
    # waitUntilStart = time.time() This needs to be deleted; otherwise it starts from 0 and behaves like regular wait

waitUntilStart = time.time()
waitUntil(2.0); click();
waitUntil(2.8); click();
waitUntil(4.8); click();

Works like a charm! Thanks again.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

LOL --- thanks for the politeness saying "... was a typ-o" ;-)

all the best.