I can't implement the rest of the function.

Asked by David Borghi on 2019-02-09

Hello.

I'm trying to add two new lines but they are not being recognized.

The function:

def do(a, b, ab, abc, ef, efg):
    if not (exists(a, 0) and exists(ab, 0)):
        return

    doubleClick(abc)
    start = time.time()

    while exists(ab, 0):
        wait(0.1)

    while time.time() < (start + 3) and exists(a, 0):
        pass

    if exists(a, 0):
        doubleClick(b)
        return

    #to be implemented, it has been ignored by the function/script.
    #It should be triggered whenever the img5 appears.
    #just to be clear, the img5 will only exist if the img1 doesn't exist

    if exists(ef, 0):
        doubleClick(efg)

while True:
    do(a="img1", b="img2", ab="img11", abc="img111", ef="img5", efg="img51")
    do(a="img1", b="img2", ab="img12", abc="img121", ef="img5", efg="img51")

I already tried removing the return, add a new pass, put a new return, but nothing has been effective.

It's just anything happens, the function is ignoring that part.

Thank you for all your help.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
David Borghi
Solved:
2 hours ago
Last query:
2 hours ago
Last reply:
2019-02-13
RaiMan (raimund-hocke) said : #1

the only reason I can see:

    while time.time() < (start + 3) and exists(a, 0):
        pass

    if exists(a, 0):
        doubleClick(b)
        return

# here we get only if img1 (a) does not exist
#... but maybe it takes longer than some 10 millisecs for img5 (ef) to get visible
#... so use some waittime > 0

    if exists(ef, 0):
        doubleClick(efg)

1) if not (exists(a, 0) and exists(ab, 0)):
        return

2) while time.time() < (start + 3) and exists(a, 0):
                 pass

    if exists(a, 0):
        doubleClick(b)
        return

______

If "a" does not exist, function exits.

If while exits when "a" is still present, if condition triggers double click and function exit.

So if "a" always exists, code after 2 may never get executed.

David Borghi (davidborghi) said : #3

@RaiMan

Thank you for your contribution.

I might not have been clear, I'm sorry about that.

The two lines I'm trying to implement are completely independent of the other functions, which means, I'd like it to be executed whenever the image img5 (ef) exists - it'll only exist when the img1 are not there (because It's impossible to have both images at the same time, either img1 will be available or img5).

Is there any other way where I can place those two lines so it can get executed anytime?

______

@Roman Podolyan

Thank you for your contribution.

I might not have been clear, I'm sorry about that.

The lines I'm referring are:

    if exists(ef, 0):
        doubleClick(efg)

I'd like it to be executed whenever the image img5 (ef) exists - it'll only exist when the img1 are not there (because It's impossible to have both images at the same time, either img1 will be available or img5).

If I was not clear, please, let me know so I can try to explain in a better way, thank you.

RaiMan (raimund-hocke) said : #4

as Roman already pointed out:

when your function starts and img1 does not exist in that moment, it will immediately return and do nothing else.

So to get to the lines beginning with the doubleClick, img1 AND img11/img12 MUST exist, when the function starts.

So the function will only get to your new 2 lines, if img1 AND img11/img12 are there, when the function starts and later img1 vanishes before < if exists(a, 0):> is executed. If img1 is still there in that moment, the function will return without getting to your 2 new lines.

you say: the new 2 lines are completely independent, so IMHO it must look like this:

def do(a, b, ab, abc, ef, efg):
    if not exists(a, 0):
        if exists(ef, 0):
            doubleClick(efg)
            return
        return
    if not exists(ab, 0)):
        return

the rest of the function is only executed if a and ab exist on entry of the function

David Borghi (davidborghi) said : #5

@RaiMan.

Thank you, this totally makes sense and I'm ashamed I couldn't figure out by myself, anyway, have in mind I'm grateful for you all.

The most part of the script worked how it should be, except by one thing (that I already read in other threads and responses but couldn't fix it).

I'll try to explain in a simple way.

The img5 is located in a place where there are variations of 3 expressions, they are:

+1 point. (Green color)
0. (White color)
-1 point. (Red color).

If I use the screenshot with the expression "-1 point" (in a red text), the script works as expected, If I use the screenshot with the expression "+1 point" (in a green text) the script ignores the screenshot and jump to the doubleClick, I understand that is something related to the image recognization, but I'm trying to understand what I should do to fix it.

For now, I'll keep trying and If I couldn't fix it, I'll comeback here, ok?

Thank you for your help.
I'm sorry for the inconvenience.