-1

I wanted to know how to move onto the next line of code after X time since this code is within a function. Currently if the code can't find the round number it continuously presses f resulting in the script getting stuck.

        if self.round in ("2-5"):
            """Levels to 5 at 2-5"""
            while arena_functions.get_level() < 5:
                self.arena.buy_xp_round() #presses f key
            print(f"\n[LEVEL UP] Lvl. {arena_functions.get_level()}")

        self.arena.fix_bench_state() #next line of code

I've tried many things but it usually results in the f key being pressed once then moving on to the next line. I want the script to keep pressings F in round 2-5 until the condition is met. If it can't meet the condition within the time limit then move onto the next line of code

Sizzles
  • 3
  • 2

2 Answers2

1

You can use the break command to break out of the loop or use continue to break out of 1 iteration of the loop.

An example to break the loop after 10 seconds:

from datetime import datetime 
start_time = datetime.now()

if self.round in ("2-5"):
            """Levels to 5 at 2-5"""
            while arena_functions.get_level() < 5:
                self.arena.buy_xp_round() #presses f key
                if ((datetime.now() - start_time).total_seconds() > 10): # check if 10 seconds passed
                    break # break out of loop
            print(f"\n[LEVEL UP] Lvl. {arena_functions.get_level()}")

        self.arena.fix_bench_state() #next line of code
Niqua
  • 386
  • 2
  • 15
0

I would insert inside the while loop a second condition, that activates after an X number of times (100 in the example).

    limit = 100
    while arena_functions.get_level() < 5 or limit != 0:
                self.arena.buy_xp_round() #presses f key
                limit = limit - 1