How do I fix this Else-If error for my platformer?

24 views Asked by At

I did not write any of this code from scratch; it's just copied from a beginner's video since I'm still new to coding in general. I know that there's possibly something wrong with the placement or the brackets and what "else is unexpected" means but I'm not sure how to go about fixing it. Here's what my code looks like:

}
else
{
    if (player_xRight > 0.5)
    {
        player_xRight -= player_friction;
    }
    else if (player_xRight < -0.5)
    {
        player_xRight += player_friction;
    }
    else
    {
        player_xRight = 0;
    }
}

This is set up the exact same way further on in the script except with the left side, yet it doesn't give me any errors like this one.

I tried rewriting the script because sometimes spaces tend to be finnicky, I know. I also tried copying the set of text that does work and replacing "left" with "right" accordingly, and I also went as far as to change the placement of some of the brackets to see if it would work. The error doesn't seem to change, though.

0

There are 0 answers