Waiting to do 1 of 2 actions

Asked by layanor on 2017-08-09


I am starting up a game for my live stream viewers so they can bet points on a fighting game I made.


Half of the code I have worked and will start up matches for me. "Lines 1 - 12"

However, the rest of the code does not work.
I checked the pictures and sikuli does see them.

Key things to know about this is, while the match is being played out, sikuli needs to be idle until a victor has won. So the amount to wait is a bit random.

Any help and improvement on this could would be great :)

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
masuo (masuo-ohara) said : #1

If either the green image or the magenta image will appear sooner or later, there is a way to wait until it appears.

while True:
    player1 = exists(greenimage,0)
    player2 = exists(magentaimage,0)

    if not player1 and not player2:
if player1:
    print "PLAYER 1 WINS"
    print "PLAYER 2 WINS"

layanor (layanor) said : #2


The code is not seeing either pic. Is there something wrong here? The pic is on the screen for about 4 - 15 seconds.

masuo (masuo-ohara) said : #3

There is not "break" in this codes.
Add break where you want to go out from while loop.
probably after click() .

layanor (layanor) said : #4

Sorry! I forgot to add the rest of the code.


layanor (layanor) said : #5

Also, I want the code to start again for the beginning after its picked the winner. That way it is completely automated with setting up the matches and declaring winners!

masuo (masuo-ohara) said : #6

# 3 comment is the last thing I can help.
You should Finish making your workflow to using "while" , "for", "if" and other things.

layanor (layanor) said : #7

I don't understand. The break is added like you suggested and does not work in this situation. In fact, this is the code you gave to me with some editing.

Can you give examples for ending workfloow with "while" , "for", "if" ?

Manfred Hampl (m-hampl) said : #8

Your code will only loop i the first "while true:" loop YOu have to put a "break" statement into the first loop.

layanor (layanor) said : #9

I rearranged the code a bit more but the loop will still not break on the first loop.


Manfred Hampl (m-hampl) said : #10

Your new code will loop forever in lines 13-15
You probably need a "break" inside this loop to continue processing below that part.

line 11 seems redundant.
The block in lines 8-10 will loop as long as that blue/red block is visible on the screen and ends when it is no more there.
I do not see the need to test whether that block now is not there any more (unless it is supposed to immediately re-appear).
In my opinion a simple "break" with a first-level indent would have been enough.

Manfred Hampl (m-hampl) said : #11

In addition to my previous comment:
You are right, the program will loop in the first while block:

A break statement will only escape the innermost loop. So the "break" in line 12 will not cause the first big loop (lines 2 - 12) to end.
As already written before, there is no need for a while statement in line 11. If you replace lines 11-12 with a simple "break" with a first level-indent (indented the same amount as line 8), then the "break" will cause an escape from the first loop (and lead to a never-ending loop in lines 13-15 as long as that part is not corrected).

By the way, I do not really understand why lines 2-12 are packed into a "while true" loop.

layanor (layanor) said : #12

Yes i have pulled a lot of code out of this. I think I have fixed most of the issues with the help I was given :) I am not going to ask a new question soon on how to speed up this code I have so far. Thank you all for the help!