Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to make an online slots click bot

I’m trying to code a bot in Python that will play a demo slot game for me. I want the bot to click a button when it appears on screen, a certain number of times. So for example, at the start of the game, the bot will click the spin button. The reels will spin and the spin button will disappear. When the reels are done spinning, the spin button will reappear, and the bot will click the spin button again.

I got the code to work, and the button is clicked infinitely by using a while True: loop (in place of the for i in range(5):). But now I’m trying to only get it to run a certain number of times, and it doesn’t work. It only clicks the button once, then the program is over.

import pyautogui

def main():
    findButton()
    clickButton()


def findButton():
    global buttonPoint 
    buttonLocation = pyautogui.locateOnScreen('kronosunleashed.png', confidence=0.40) #Locates button on screen
    buttonPoint = pyautogui.center(buttonLocation) #Finds center of button


def clickButton():
    for i in range(5):
        buttonX, buttonY = buttonPoint
        pyautogui.click(buttonX, buttonY) #Clicks center of button

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Perhaps it goes too fast for the program to notice. Try adding a sleep in the loop

import time

def clickButton():
    for i in range(5):
        buttonX, buttonY = buttonPoint
        pyautogui.click(buttonX, buttonY) #Clicks center of button
        time.sleep(1) # waits a second
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading