Why is my character animation going out of range

I'm trying to get a punch Animation working for my character. But when I run the game I press the key to punch and when it finishes the animation the game gets an error

\Desktop\python projects\Ultamate Brawl\Ultamite BRAWL.py", line 41, in redrawGameWindow
   win.blit(PunchR[punchcount//2], (xcor, ycor))
       IndexError: list index out of range
[Finished in 6.4s]

an I looked at my code and it looks fine

def redrawGameWindow():
    global punchcount 
    global walkcount

    win.blit(bg, (-70,0))
    if walkcount + 1 >= 27:
        walkcount = 0
    if punch == True:
        if punchcount > 49:
            punchcount = 1
        win.blit(PunchR[punchcount//2], (xcor, ycor))
        punchcount += 1
    elif isjump:
        win.blit(superjump, (xcor,ycor))
    elif left:
        if walkcount > 49:
            walkcount = 1
        win.blit(walkLeft[walkcount//4], (xcor, ycor))
        walkcount += 1

    elif right:
        win.blit(walkRight[walkcount//4], (xcor,ycor))
        walkcount += 1
        win.blit(char, (xcor,ycor))


Read more here: https://stackoverflow.com/questions/64406097/why-is-my-character-animation-going-out-of-range

Content Attribution

This content was originally published by Zina at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: