Waiting to do 1 of 2 actions

Asked by layanor

Hello!

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

https://gyazo.com/68eddbbdc23c238bcd6828977ddf0f79

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

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
layanor
Solved:
Last query:
Last reply:
Revision history for this message
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:
        sleep(0.5)
        continue
    else:
        break
if player1:
    print "PLAYER 1 WINS"
else:
    print "PLAYER 2 WINS"

Revision history for this message
layanor (layanor) said :
#2

https://gyazo.com/e0a916124999037281e150a98d4603c5

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

Revision history for this message
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() .

Revision history for this message
layanor (layanor) said :
#4

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

https://gyazo.com/dd9520432ac9fa38ecb958e1ab4b3f33

Revision history for this message
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!

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

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

Revision history for this message
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" ?

Revision history for this message
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.

Revision history for this message
layanor (layanor) said :
#9

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

https://gyazo.com/a5fec13cf88d61ff488821490c7f8b38

Revision history for this message
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.

Remark:
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.

Revision history for this message
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.

Revision history for this message
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!