VSC Compiler not showing animation but .exe does

Hello,

I have an issue during this chapter (Udemy C++ Fundamentals Castle Clash Chapter. 18: Enemy Class) where when I compile and test in VSC it doesn’t show the idle animation of the goblin or warrior; but if i run the .exe it will. Has anyone ran into this issue before?

Up until this chapter (Enemy Class) I had no issues. I have vetted the code to the best of my ability to compare it to the chapter provided commits but I have no doubt I may have missed something. It is just unusual to me that it would run fine through the .exe and not through VSC.

I can post the code for each file if necessary but wanted to see if this is a known issue first.

VSC Ver: 1.85.0
raylib 5.0
C++ Skill Level: beginner

I haven’t come across this issue personally, but would certainly like to take a look for you!

Rather than posting your code, we can save each other a little time by having you upload your project using this form. That way I can access your project precisely as you have it.

Thank you so much for the quick response.

Some added symptoms are that sometimes I lose connection to raylibs and/or the compiler. Unless I open the project from “main.code-workspace”, it will give me error squigglies for the raylib includes.

For example: all the other projects in the Udemy course I could open from the “main.cpp.” This project will not allow me to do so without the raylib errors.

I’m not sure if you’re referring to the same course. But with this course we’re making references to outside resources. The code-workspace file allows us to load the entire project, which has configuration files contained in the .vscode folder of the project and as well as configuration in the makefile.

For C++ projects that don’t reference outside libraries, you can usually open any main.cpp file and compile. But in our case the compiler wouldn’t know where to look for raylib so that’s what the other files are for.

As for the animation issue, I found the problem on line 23 in character.h where you don’t initialize the variable runningTime:
float runningTime; should be float runningTime{}; or runningTime = 0;

The reason for this is that runningTime would end up getting initialized to anything if the compiler doesn’t know what to set it to. And sometimes it gets initialized to some value far below 0, so it would take a really long time but eventually the knight would start animating.

You also have this problem in enemy.h, you’re just getting lucky.

Tuomo,

Thank you for spending the time and energy towards my learning adventure; I had been anxiously awaiting your response!

Your explanation about the runningTime then getting initialized to anything explains the intermittent test results I was getting. It also makes sense that enemy.h has the same error as it was copy and pasted from character.h. Thank you for checking my work and I will be more diligent going forward.

Sincerely, thank you to this course, this site, and your willingness to help.

You’re welcome! I’m glad I could help.

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

Privacy & Terms