Novice Question - Using pyautogui to execute if or statements using locateCenterOnScreen

Hello Everybody,

I am very new to programming and am looking to make a program to perform a repetitive, 30-40 second task in a video game. I watched a video regarding locating the center coordinates of a specific image using pyautogui, but am not fully comprehending how to implement this into what I want to build.

Specifically, there will be two dialogue boxes that pop up after you drop a fishing rod into water, one of them says “No fish” and the other says “You caught a fish”. How would the program be able to read and perform two different commands based on what it sees in the dialogue box? (Fish = move on to catch), (No fish = left click and drop rod again).

Thank you all for the insight and advice. I very much appreciate it.

I have never heard of writing any program to control a video game unless the video game allows it via a mod of some sort.

I don’t want to be discouraging, but I think this is a difficult problem to solve, even for an experienced developer. And yes, per above, many games are unfriendly to automation, whether intentionally (anti cheat) or incidentally.

I’m not familiar with pyautogui, so I can’t offer any specific guidance about it. But see if their documentation talks about reading text or OCR – you’ll need some way to recognize which game state you’re in.

I think it’s important to understand that this is hard. Try it, have fun, and try to learn a bit in the process. But don’t feel that you have personally failed if it doesn’t work – games sometimes have intentional, built in hindrances for automation.