#๐Ÿ”’ while loop won't break, even when the condition is met

44 messages ยท Page 1 of 1 (latest)

peak zincBOT
#

@faint cedar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

crisp iris
#

How did you verify that the condition was met?

junior ridge
#

Maybe try printing the value with pixel(x, y)

#

To verify it

toxic dew
#

It's been a long day but aren't those conditions reversed?
ie in one it breaks when not matches color, in the other when it matches color

#

Would be a lot simpler using break imho ๐Ÿ˜‰

junior ridge
#

Try adding that sleep to the one with if condition

fierce crane
#

just use a break with a if statement

crisp iris
#

the break will only break the while loop, not the for loop

fierce crane
#

which loop are you trying to break X_X

crisp iris
#

and the pag.press

fierce crane
#

so you want to break the while loop right?

#

just put a if statement inside the while loop and if that statement is true it sould break

crisp iris
#

does it work if you comment out the pag.press

#

does it print the i can see it even once or not at all

fierce crane
#

what if you put if condition for the while loop?

#

outside

crisp iris
#

does it even enter the for loop?

#

Have you confirmed that the code is reaching the for loop?

junior ridge
#

You want it to click if it matches the color?

#

Cuz now its clicking if it doesnt match the color

#

So if the color is present it skips to printing I can see it

wary cobalt
#

Put multiple print calls - at the beginning of the for loop, then inside the while (and print pixel colour then as well)

fierce crane
#

wait a sec the print is not in the while loop :/

#

the main problem is we don't know what we are trying to help with X_X and what's the output its spamming or giving any error :<> and the problem u having with the while loop (except it breaking it)

#

so everything works??

crisp iris
#

Is there anything else above it that may influence it?

fierce crane
slow valley
#

Maybe try adding some breakpoints and follow your code and/or manually check the condition?

fierce crane
#

Did you try somthing like this? (idk what am i doing)

for i in range(8):
    pag.press(str(i+1)
    t.sleep(.2
    while True:
      if not pag.pixelMatchesColor(960, 601, (198, 198, 198)):
          pag.rightClick()
          t.sleep(random.uniform(.2, .3))
          break

    print("I can see it")
#

what about something like this?

    while True:
          pag.rightClick()
          t.sleep(random.uniform(.2, .3))
          if pag.pixelMtchesColor(960, 601, (198, 198, 198)):
            break

???

junior ridge
#

Try printing rgb values of that pixel

fierce crane
#

:o

#

How about this? man my head hurts lol the for loop XD

for i in range(8):
    pag.press(str(i+1)
    t.sleep(.2
    if not pag.pixelMtchesColor(960, 601, (198, 198, 198)):
       while True:
          pag.rightClick()
          t.sleep(random.uniform(.2, .3))
          if pag.pixelMtchesColor(960, 601, (198, 198, 198)):
            break
#

welp

junior ridge
#
for i in range(8):
    pag.press(str(i+1)
    t.sleep(.2)
    while not pag.pixelMatchesColor(960, 601, (198, 198, 198)):
        print(f"Failed to match because the color is {pag.pixel(960, 601)}")
        pag.rightClick()
        t.sleep(random.uniform(.2, .3))

    print("I can see it")
fierce crane
#

bru

#

Your welcome

peak zincBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.