#๐Ÿ”’ help

52 messages ยท Page 1 of 1 (latest)

autumn raven
#

why does my code work once and dies when i alt tab and go back it works then dies

halcyon flameBOT
#

@autumn raven

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.

unreal bison
#

I don't understand why you are using pickle here.

#

also is there a reason you need to use both pyautogui and pydirectinput?

autumn raven
#

im not sure if i can use only pyautogui

autumn raven
unreal bison
#

I know e-kreten mentioned pickle before but the only time you really need to use pickle is if you are storing data to remember it between stopping the program and starting it again

autumn raven
#

then how can i save the value of white_or_blue() while in a loop?

unreal bison
#

a few things though: you don't need to do if file == True:, you can just do if file:. You can also just do if Path('temp').unlink(): so you don't need to store that value to file anyways.

#

hang on let me look at the white_or_blue function

#

oh, you're just calling it in click_value

#

Do you know how to return values from functions?

#

!e ```py
def f():
return "Hello"
s = f()
print(s)

halcyon flameBOT
#

@unreal bison :white_check_mark: Your 3.12 eval job has completed with return code 0.

Hello
autumn raven
#

like this ?
if Path('temp').unlink():
pass

unreal bison
#

if that returns True or False sure

autumn raven
#

it needs to be run while in the loop

unreal bison
#

What do you mean? You're calling it within the click_value function, writing to the file, then after you exit the white_or_blue function you are almost immediately just reading the value from the file again

autumn raven
#

white_or_blue() looks for a pixel if i run it before a pixel exists its gonna be wrong

unreal bison
#

There's literally maybe four lines of code from when you return from that function and the next code that is executed is when you read the value you dumped to file. Is the delay between writing to and reading from disk what's making it work for you?

#

Oh I think I see what you're doing

autumn raven
#

i mean it works but if you know of a better way ill do it

autumn raven
unreal bison
#

When you say it dies what do you mean?

#

does it throw an error and exit?

autumn raven
#

what the code does is alt if its white key up wait key down then if blue then right click then get a value of where to click if the file exists take the value of not get it it looks for a white pixel then gets it then move to the area and click this works the 1st time but 2nd 3rd and more just right click and key up alt then restart then loop but if i alt tab and go back it works 1 more time then dies

unreal bison
#

So you mean nothing happens? Does the program exit?

autumn raven
#

no it just does the loop but doesnt move and click

unreal bison
#

Do you see any of your error messages printing?

#

I'd suggest putting a print statement before each time you click something so you can know the control flow is reaching that point in your program.

autumn raven
unreal bison
#

What do you mean it didn't really work?

#

Did the print statements not print?

autumn raven
#

no they all did

unreal bison
#

So your program is clicking

autumn raven
#

no it should but it isnt

unreal bison
#

So inside click(location) if you put a print statement before and after pyautogui.leftClick(location, duration=0.3) and they both print, that means the code is working (maybe not as you intended. So if it's not, then perhaps your location is incorrect. Is it possible when you alt-tab between the windows that the actual spot you want to click is changing?

autumn raven
#

no

#

and wouldnt i get an error

#

or see the mouse move

unreal bison
#

if it clicked? you aren't printing an error message if it clicks are you?

#

It looks like you've got two hardcoded locations you are telling it to click. Is it possible the game window itself (I'm assuming this is a game) is changing so it no longer displays what you think it is?

#

therefore it will read the wrong color and you will click at the wrong location?

#

Does that happen? Does the screen change at all?

autumn raven
#

no its doesnt change

unreal bison
#

Ok. Maybe somebody else has an idea then. Sorry I couldn't help you.

autumn raven
#

np thanks anyways

halcyon flameBOT
#
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.