Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python API commands miss or add inputs #166

Open
VulshokBersrker opened this issue Dec 18, 2024 · 1 comment
Open

Python API commands miss or add inputs #166

VulshokBersrker opened this issue Dec 18, 2024 · 1 comment

Comments

@VulshokBersrker
Copy link

I wrote a python script to automate Pokemon BDSP Shiny Egg Farming. It works by using the Python API points create_controller() and press_buttons(). But the script messes up at random times because NXBT skips an input or adds an input.

I'm running:
Ubuntu 24.04.1 LTS
Python 3.11.11

I also use time.sleep() to slow down the inputs to lower the chance of inputs failing. I have custom functions for a single key press, multiple presses, and hold down the key.
Here's an example:

def Key_Press_Multi(key, numPresses):
    for i in range(numPresses):
        nx.press_buttons(controller_index, key, down=0.1)
        time.sleep(0.7)

Function using the custom functions

def Move_To_Man_From_PokeCenter():
    global current_egg_count
    print("-- Walking to the Daycare man --")
    # ---- WALK TO THE DAYCARE MAN ---- 
    # Left 6 Steps
    Key_Press_Multi(DPAD_LEFT, 6)
    # Move Up 10 Steps
    Key_Press_Multi(DPAD_UP, 10)
    # Left 7 Steps
    Key_Press_Multi(DPAD_LEFT, 7)

    # ---- DIALOGUE SECTION ---- 
    print("-- Getting a new egg --")
    time.sleep(1)
    Key_Press_Multi(A, 8)
    time.sleep(4)
    Key_Press_Multi(A, 2)
    time.sleep(6)
    Key_Press_Multi(B, 2)
    time.sleep(4)
    Key_Press_Once(B)
    time.sleep(2.2)
    current_egg_count += 1
    
    # ---- FROM DAYCARE MAN TO BIKE LANE ---- 
    print("-- Walking from Daycare man to biking lane --")
    # Move Right 6 Steps
    Key_Press_Multi(DPAD_UP, 3)
    Key_Press_Multi(DPAD_RIGHT, 7)
    time.sleep(0.5)
    # READY TO BIKE UP AND DOWN
    Key_Press_Once(SELECT)
    time.sleep(0.3)
    Key_Press_Once(DPAD_UP)
    print("In Position - Ready to Bike")

What will often happen is if an input does mess up, they will walk one more step, or one less step. And that will ruin the afk script.

Is there any solution to this?

@DeathBerry-dev
Copy link

Hey did you ever work out this issue? I am having similar issues where inputs are missed even after giving large enough delays (from 0.5s to multiple s) I believe the time.sleep causes some issues as I tried adding it to some functions but it caused an issue nearly immediately adding a input so I try putting al delays into the MACRO = """macro""" which I found helped, I also removed all loops but un sure if that helps or not, did notice less mess ups afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants