0

I am trying to automate android game. I have so many methods so I break my code in 3 parts. main, functions and collectors. I have a method in functions which is:

def search_image(image, confidence=.6, click=True):
location = pyautogui.locateCenterOnScreen(image, confidence=confidence)
if location is not None:
    if click:
        pyautogui.click(location)
    return location
else:
    return False

But I cant access it in collectors, like this:

from functions import*
def collect_product():
    if search_image(r'Resources\NewOrderAvailable.png') is not False:
        search_image(r'Resources\NewOrderAvailable2.png')
        for item in range(0, 6):
            search_image(r'Resources\Collect.png', confidence=.8)
        search_image(r'Resources\Back.png')
        search_image(r'Resources\CloseOrderMenu.png')
    else:
        return False

I got NameError: name 'search_image' is not defined. I need to duplicate that method to make it work. I was wondering what went wrong and how to fix it?

2 Answers 2

1

Your function is not an instance of the class. You need to add a self keyword to make it accessible outside.

def search_image(self, image, confidence=.6, click=True):
location = pyautogui.locateCenterOnScreen(image, confidence=confidence)
if location is not None:
    if click:
        pyautogui.click(location)
    return location
else:
    return False
Sign up to request clarification or add additional context in comments.

Comments

1

Try

import functions

functions.search_image('...')

1 Comment

I tested it just a moment ago. You have no whitespace between import and *

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.