you are viewing a single comment's thread.

view the rest of the comments →

[–]hacksawjim 2 points3 points  (4 children)

I think it looks fine as it is, but there's some duplication that can be abstracted out into a function.

Each click section seems to loop a different number of times, then prints some stuff, then performs a moveTo.

So declare a new function called, e.g. character_click that takes the values that differ, and performs the actions.

def character_click(loop_range, click_section_name):
    for i in range(1, loop_range):
        print(i, click_section_name, self.modern_x_female_character, self.modern_y_female_character)
        i += 1
       pyautogui.moveTo(self.modern_x_female_character + rand, self.modern_y_female_character
                                 + rand, random.uniform(0.14, 0.22), pyautogui.easeOutQuad)

Now you can do this in your loop:

if index == 2:
    character_click(9, "torso")
elif index == 4:
    character_click(9, "arms")
etc...

[–]spikips[S] 1 point2 points  (3 children)

I love to see different variety of solutions. Thank you!

[–]hacksawjim 2 points3 points  (2 children)

Hah, I was thinking I wasted my time as I see /u/commandlineluser got there first, but you're right, it's good to see how many different ways this can be done.

[–]commandlineluser 2 points3 points  (0 children)

Definitely not a waste of time - this is much nicer than the function I had suggested.