Code works fine so far, however getting odd errors

Hey

So I’ve been encountering errors that don’t appear in the instructors code - even after copying their exact code from git. it throws up an error dialogue but if i choose debug anyway the game runs as expected.

This one is asking for a } in the middle of a //comment

image

and this one is asking for ; somewhere. I’ve scoured the code and can’t figure it out.

a lot of the text for my variables are staying white instead of changing to blue, which i think is related, it wasn’t happening until these errors.

code:

#include “raylib.h”

struct AnimData

{

Rectangle rec;

Vector2 pos;

int frame;

float updateTime;

float runningTime;

};

int main()

{

//window dimensions

const int windowWidth{512};

const int windowHeight{380};

// initialize the window

InitWindow(windowWidth, windowHeight, "Dapper Dasher!");

// acceleration due to gravity (pixels/s)/s

const int gravity{1'000};

// nebula variables

Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");

// AnimData for nebula

AnimData nebData{

    {0.0, 0.0, nebula.width/8.f, nebula.height/8.f}, // Rectangle rec

    {windowWidth, windowHeight - nebula.height/8.f}, // Vector2 pos

    0, // int frame

    1.0/12.0, // float updateTime

    0 // float runningTime

};

AnimData neb2Data{

    {0.0, 0.0, nebula.width/8.f, nebula.height/8.f},

    {windowWidth + 300, windowHeight - nebula.height/8.f},

    0,

    1.0/16.0,

    0.0

};

// nebula X velocity (pixels/second)

int nebVel{-200};

// scarfy variables

Texture2D scarfy = LoadTexture("textures/scarfy.png");

AnimData scarfyData;

scarfyData.rec.width = scarfy.width/6;

scarfyData.rec.height = scarfy.height;

scarfyData.rec.x = 0;

scarfyData.rec.y = 0;

scarfyData.pos.x = windowWidth/2 - scarfyData.rec.width/2;

scarfyData.pos.y = windowHeight - scarfyData.rec.height;

scarfyData.frame = 0;

scarfyData.updateTime = 1.0/12.0;

scarfyData.runningTime = 0.0;

// is the rectanlge in the air?

bool isInAir{};

// jump velocity (pixels/second)

const int jumpVel{-600};

int velocity{0};

SetTargetFPS(60);

while (!WindowShouldClose())

{

    // delta time (time since last frame)

    const float dT{GetFrameTime()};

    // start drawing

    BeginDrawing();

    ClearBackground(WHITE);

    // perform ground check

    if (scarfyData.pos.y >= windowHeight - scarfyData.rec.height)

    {

        // rectangle is on the ground

        velocity = 0;

        isInAir = false;

    }

    else

    {

        // rectangle is in the air

        velocity += gravity * dT;

        isInAir = true;

    }

    // jump check

    if (IsKeyPressed(KEY_SPACE) && !isInAir)

    {

        velocity += jumpVel;

    }

    // update nebula position

    nebData.pos.x += nebVel * dT;

    // update the second nebula's position

    neb2Data.pos.x += nebVel * dT;

    // update scarfy position

    scarfyData.pos.y += velocity * dT;

    // update scarfy's animation frame

    if (!isInAir)

    {

        // update running time

        scarfyData.runningTime += dT;

        if (scarfyData.runningTime >= scarfyData.updateTime)

        {

            scarfyData.runningTime = 0.0;

            // update animation frame

            scarfyData.rec.x = scarfyData.frame * scarfyData.rec.width;

            scarfyData.frame++;

            if (scarfyData.frame > 5)

            {

                scarfyData.frame = 0;

            }

        }

    }

    // update nebula animation frame

    nebData.runningTime += dT;

    if (nebData.runningTime>= nebData.updateTime)

    {

        nebData.runningTime = 0.0;

        nebData.rec.x = nebData.frame * nebData.rec.width;

        nebData.frame++;

        if (nebData.frame > 7)

        {

            nebData.frame = 0;

        }

    }

    // update nebula animation frame

    neb2Data.runningTime += dT;

    if (neb2Data.runningTime >= neb2Data.updateTime)

    {

        neb2Data.runningTime = 0.0;

        neb2Data.rec.x = neb2Data.frame * neb2Data.rec.width;

        neb2Data.frame++;

        if (neb2Data.frame > 7)

        {

            neb2Data.frame = 0;

        }

    }

    // draw nebula

    DrawTextureRec(nebula, nebData.rec, nebData.pos, WHITE);

    // draw the second nebula

    DrawTextureRec(nebula, neb2Data.rec, neb2Data.pos, RED);

    // draw scarfy

    DrawTextureRec(scarfy, scarfyData.rec, scarfyData.pos, WHITE);

    // stop drawing

    EndDrawing();

}

UnloadTexture(scarfy);

UnloadTexture(nebula);

CloseWindow();

}

Hey!
I copied your code and I didn’t get any errors. it works well !
Did you try to “start debugging” ? (even with the error)

Sometimes VS code can highlight errors when everything is normal (Often due to Refactoring), and after the compilation it realizes that everything “is ok” and remove the highlight.

At the risk of sounding like a broken record, I too couldn’t find an issue with your code. Like Inraste says, intellisense is not always “intelligent” and will give incorrect errors until you compile your code.

hey thanks guys, yeah it was weird and compiling didn’t seem to fix it. I closed and opened the project and all the errors disappeared. :man_shrugging:

That’s also a totally valid and acceptable troubleshooting step and solution!

The golden rule of tech, turn it off and on again!

1 Like

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

Privacy & Terms