Defined function is looping

Asked by David

Hi
I am having an issue that makes no sense to me. The defined function ClickVideo is looping.

Yes, I do have a recursive call. But this is not where it is looping. I read on another post your comments about recursive calls. This call is only to address an error should one appear.

I added popups through out my code so I could follow it as it ran. So as it runs, this is the popups I am getting (9, 1, 2, (3,4,5, or 6), 11; 1, 2, (3,4,5, or 6), 11; 1, 2, (3,4,5, or 6), 11; etc.)
What I was expecting was (9, 1, 2, (3,4,5, or 6), 11; 9, 1, 2, (3,4,5, or 6), 11; etc.). After function runs, I am expecting it to go back to waiting for a change to region R1.

That says to me that my function is looping. Should I have a terminator on my function?

R1 = find(Pattern("1470246838908.png").similar(0.90))
R2 = find("1470253780841.png")
B1 = Region(R2.x+21, R2.y+18, 72, 77)
B2 = Region(R2.x+104, R2.y+18, 72, 77)
B3 = Region(R2.x+190, R2.y+18, 72, 77)
B4 = Region(R2.x+273, R2.y+18, 72, 77)
Watched = 0
vSet = 1

# Change video set
def ClickSet(event):
    global vSets
    if vSets == 2:
        click("1470278088532.png")
    if vSets == 3:
        click("1470278122703.png")
    if vSets == 4:
        click("1470278147590.png")
    if vSets == 5:
        click("1470278175919.png")
    if vSets == 6:
        click("1470278203403.png")
    wait(5)

# Click next video
def ClickVideo(event):
# R1.stopObserver()
    global Watched
    Watched = Watched + 1
    popup("1")
    if exists("1470276113431.png"):
        popup("2")
        if B1.exists("1470266612550.png"):
            B2.click()
            popup("3")
        elif B2.exists("1470266612550.png"):
            B3.click()
            popup("4")
        elif B3.exists("1470266612550.png"):
            B4.click()
            popup("5")
        elif B4.exists("1470266612550.png"):
            click("1470275832696.png")
            wait(5)
            B1.click()
            popup("6")
        else:
            popup("Nothing is playing now")
            exit()
    else:
        popup("7")
        #start next set
        vSet = vSet + 1
        ClickSet()
        B1.click()
    wait(5)
    popup("11")
    #if error appears play next video
    if exists("1469490503735.png"):
        Watched = Watched - 1
        popup("8")
        ClickVideo()

#Watch 500 videos
while Watched <= 500:
    popup("9")

    R1.onChange(50, ClickVideo)
    R1.observe()

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
masuo
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

I see two different but similarly named variables, vSet and vSets, is that on purpose? vSets is never set!

Revision history for this message
David (davper) said :
#2

No, that was not intentional. Thank You.
But I haven't gotten far enough into the script yet for that to become an issue. So my original problem still exists.

Revision history for this message
David (davper) said :
#3

HI
No One?

Revision history for this message
Best masuo (masuo-ohara) said :
#4

This is my sample code for study for onChange.
This might be your help.

Settings.UserLogs = True
Settings.UserLogTime = True
def handler(event):
    global status
    event.stopObserver()
    Debug.user("onChange")
    status = "retry"

r = Region(91,4,422,69)
r.onChange(handler)
status = "start"
for cnt in range(30):
    r.observe(FOREVER,background=True)
    status = "wait"
    Debug.user("wait onChange")
    while status == "wait":
        wait(1)
    wait(3)

Revision history for this message
David (davper) said :
#5

Thanks masuo, that solved my question.