Python Forum
Array issues - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Array issues (/thread-28387.html)



Array issues - Bmart6969 - Jul-17-2020

Getting a too many indices for array error while trying to make a function repeat. Is there a way to remove Array data or overwrite it maybe?
def Begin():
    RAtext = pyautogui.locateOnScreen("RAtext.png")

    while RAtext == None:
        Anvil = pyautogui.locateCenterOnScreen("Anvil.png", grayscale=False, confidence=0.7)
        print((Anvil), "anvil")
        Anvil1 = np.array(Anvil)
        Anvil1[0] += xrand
        Anvil1[1] += yrand
        print((Anvil1), "Anvil1")
        Anvil1 = region = Anvil1[0], Anvil1[1]
        time.sleep(0.1)
        pyautogui.moveTo(Anvil1, duration=0.3)
        pyautogui.click()
        time.sleep(0.4)
        Anvil1 = Anvil
        RAtext = pyautogui.locateCenterOnScreen("RAtext.png", confidence=0.9)
        print((RAtext), "RAtext")
        if pyautogui.locateOnScreen("UnselectedRune.png") != None:
            print("Selecting Rune Bars")
            Unselected = pyautogui.locateCenterOnScreen("UnselectedRune.png", grayscale=False)
            print(Unselected)
            Unselected1 = np.array(Unselected)
            Unselected1[0] += xrand
            Unselected1[1] += yrand
            print(Unselected1)
            Unselected1 = region = Unselected1[0], Unselected1[1]

            pyautogui.moveTo(Unselected1, duration=0.3)
            pyautogui.click()
            time.sleep(0.5)
            Scroll = pyautogui.locateCenterOnScreen("Wtext.png", confidence=0.9)
            print(Scroll)
            pyautogui.moveTo(Scroll, duration=0.3)
            time.sleep(0.2)
            pyautogui.scroll(-400)
            time.sleep(0.3)
            pyautogui.scroll(-600)
            RuneArrowheads = pyautogui.locateCenterOnScreen("RuneArrowheads.png", confidence=0.9)
            RuneArrowheads1 = np.array(RuneArrowheads)
            RuneArrowheads1[0] += xrand
            RuneArrowheads1[1] += yrand
            print(RuneArrowheads1)
            RuneArrowheads1 = region = RuneArrowheads1[0], RuneArrowheads1[1]

            pyautogui.moveTo(RuneArrowheads1, duration=0.2)
            time.sleep(0.1)
            pyautogui.click()
            BeginProject = pyautogui.locateCenterOnScreen("BeginProject.png")
            BeginProject1 = np.array(BeginProject)
            BeginProject1[0] += xrand
            BeginProject1[1] += yrand
            print(BeginProject1)
            BeginProject1 = region = BeginProject1[0], BeginProject1[1]

            pyautogui.moveTo(BeginProject1, duration=0.3)
            pyautogui.click()

        elif RAtext != None:
            BeginProject = pyautogui.locateCenterOnScreen("BeginProject.png")
            BeginProject1 = np.array(BeginProject)
            BeginProject1[0] += xrand
            BeginProject1[1] += yrand
            print(BeginProject1)
            BeginProject1 = region = BeginProject1[0], BeginProject1[1]

            pyautogui.moveTo(BeginProject1, duration=0.3)
            pyautogui.click()
            RAtext = None
            time.sleep(smithtime)
def repeat(f, n):
     for i in range(n):
        f()
repeat(Begin(), 3)
errors
File "C:/Users/brady/PycharmProjects/rsBot/runearrowheads.py", line 125, in <module>
repeat(Begin(), 3)
File "C:/Users/brady/PycharmProjects/rsBot/runearrowheads.py", line 59, in Begin
Anvil1[0] += xrand
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed


RE: Array issues - ndc85430 - Jul-18-2020

Why is your array 0-dimensional in the first place? It's not an array then. What is Anvil (i.e. what type is it)?