Python Forum
naming images adding to number within multiple functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
naming images adding to number within multiple functions
#1
I am trying to map an image within a game that is a scrollable background. I am trying to figure out how to name the screenshots taken and adding +1 to the image name after every screenshot is taken however it is 3 functions within a function and i'm running into a dead end as i cannot get it to update a string either outside or within the functions, or maybe i am and it's reverting it back to 0. is it possible to do it using a global variable or is there a better way?
def f(x):
    print(currentnumber + x)
currentnumber = 0

def leftscroll():
    def f(x):
        global currentnumber
        print(currentnumber + x)
        currentnumber += 1
    screenshot = r'C:\Users\brady\PycharmProjects\Bot\map' + str(currentnumber) + '.png'
    pyautogui.moveTo(x=193, y=474, duration=0.2)
    pyautogui.screenshot(screenshot,region=(193,180,727,294))
    pyautogui.mouseDown(button='left')
    pyautogui.moveTo(x=990,y=474, duration=0.5)
    time.sleep(0.4)
    pyautogui.mouseUp(button='left')
    return


#next row


def scrollup():
    def f(x):
        global currentnumber
        print(currentnumber + x)
        currentnumber += 1
    screenshot = r'C:\Users\brady\PycharmProjects\Bot\map' + str(currentnumber) + '.png'
    pyautogui.moveTo(x=193, y=180, duration=0.3)
    pyautogui.mouseDown(button='left')
    pyautogui.moveTo(x=193, y=474, duration=0.5)
    time.sleep(0.5)
    pyautogui.mouseUp(button='left')
    pyautogui.screenshot(screenshot, region=(193,180,727,294))
    return
def rightscroll():
    def f(x):
        global currentnumber
        print(currentnumber + x)
        currentnumber += 1
    screenshot = r'C:\Users\brady\PycharmProjects\Bot\map' + str(currentnumber) + '.png'
    pyautogui.moveTo(x=990, y=474, duration=0.2)
    pyautogui.mouseDown(button='left')
    pyautogui.moveTo(x=193,y=474, duration=0.5)
    time.sleep(0.4)
    pyautogui.mouseUp(button='left')
    pyautogui.screenshot(screenshot, region=(193,180,727,294))
    return
def repeat_fun(times, j):
    for i in range(times): j()



while pyautogui.locateOnScreen('endimage.png') == None:
    def f(x):
        global currentnumber
        print(currentnumber + x)
        currentnumber += 1
    repeat_fun(5,leftscroll)
    print(currentnumber)
    pyautogui.locateOnScreen('endimage.png', confidence=0.8)
    scrollup()
    print(currentnumber)
    repeat_fun(5,rightscroll)
    print(currentnumber)
    pyautogui.locateOnScreen('endimage.png', confidence=0.8)
    scrollup()

got it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  naming entities(city abbreviations) tirumalaramakrishna 1 1,198 May-06-2022, 11:22 AM
Last Post: jefsummers
  Adding an ascending number [SOLVED] AlphaInc 3 2,204 Jul-11-2021, 10:13 AM
Last Post: perfringo
  Python Style and Naming Variables rsherry8 3 2,170 Jun-07-2021, 09:30 PM
Last Post: deanhystad
  Naming the file as time and date. BettyTurnips 3 2,889 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  How to call multiple functions sequentially Mayo 2 9,160 Jan-06-2021, 07:37 PM
Last Post: Mayo
  naming conventions mvolkmann 4 2,095 Sep-28-2020, 05:51 PM
Last Post: Gribouillis
  multiple number format conversion oli_action 4 2,531 Aug-11-2020, 05:10 AM
Last Post: perfringo
  Defining multiple functions in the same def process sparkt 5 2,753 Aug-09-2020, 06:19 PM
Last Post: sparkt
  Question about naming variables in class methods sShadowSerpent 1 1,961 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  adding elements to a list that are more than a specific number Olavv 2 2,151 Mar-19-2020, 06:05 PM
Last Post: Olavv

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020