This 'if' clause does not guard

So I’ve been able to work everything out thus far, but I get this error quite often and want to see if there’s some kind of foundational knowledge I’m missing that keeps this error popping up.

It doesn’t seem like I should be able to mess it up between finishing a line and starting a new one. It happens directly after I add the ‘if’ statement, and will not go away. I’ve been able to erase and start again but this one won’t go away.

#include "raylib.h"
int main()

{
    //Window Dimensions
    const int FrameHeight {380};
    const int FrameWidth {512};

    //Initialize Window
    InitWindow( FrameWidth, FrameHeight, "Dapper Dasher!");

    // Rectangle Dimensions
    const int width {50};
    const int height {80};

    int PosY {FrameHeight - height};
    int velocity {0};

    

    SetTargetFPS(60);
    while (!WindowShouldClose())
    {
        //Start Drawing
        BeginDrawing();
        ClearBackground(WHITE);

        if (IsKeyPressed(KEY_SPACE));
        {
            velocity -= 10;
        }

        PosY += velocity;

        DrawRectangle(FrameWidth/2, PosY, width, height, RED);

        //Stop Drawing
        EndDrawing();
    }
    CloseWindow();
}

Don’t put semi-colons after an if-statement. The semi-colon is meant to be an “end of statement” in your code and if-statements are meant to act like “if X is true, then do Y”. Placing a semi-colon cuts off the “then do Y” portion.

Ahh…I knew it was something simple like that that I was missing. Thank you. I ended up getting it to work but I didn’t even notice that I had done that till you pointed that out.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms