Getting these errors when I’m trying to run the code.
These are referring to parts of my ofApp.cpp (player_1.update() and player_1.draw() stuff like that):
void ofApp::setup(){
//Initialises the game_State as the start state.
//This will take the player to the "title screen"
game_state = "start";
//Initialises the players score at 0.
score = 0;
//Loads the FalconDragoon's sprite for the player object.
player_image.load("assets/player/falconDragoon.png");
player_1.setup(&player_image);
}
//Whitespace to help me tell where one void ends and another begins.
//--------------------------------------------------------------
void ofApp::update(){
//When the game is initially started...
if (game_state == "start") {
}
//When the game is moved into the main gameplay loop...
else if (game_state == "game") {
//Updates the player object during the gameplay loop.
player_1.update();
}
//When the game ends (game over)...
else if (game_state == "end" ) {
}
}//end void
//--------------------------------------------------------------
void ofApp::draw(){
//When the game is initially started...
if (game_state == "start") {
}
//When the game is moved into the main gameplay loop...
else if (game_state == "game") {
//Draws the player on screen.
player_1.draw();
}
//When the game ends (game over)...
else if (game_state == "end" ) {
}
}//VOid end
Undefined reference means the cpp file (ie player.cpp) was not compiled. Do you have this in your project ? The h file is enough to help files like ofapp.cpp compile but you need to have the player.cpp compiled when it goes to link.
Also if helpful you may want to read a little about the compile process — you can have errors in different stages and the more you know what’s happening when the easier it may be to debug Compiling and Linking in C++ - C++ Articles
In general when I see undefined reference my first thought is, am I missing a cpp file? Sometimes with different IDEs you can add a file but it’s not set to be part of the project. (On osx I think this is “add to target”)
The h file is just a kind of “list of ingredients” but in this case, the function hasn’t really been written out anywhere. You might want to read about function definition vs declaration. It’s Similar to how ofApp h and cpp work with update and draw….
The are declared but not defined - meaning you said what the fun thing is called and what Params it takes but it hasn’t actually been implemented. Please look at ofapp.h and ofapp.cpp to see how update and draw are written in both places.
Also if it helps, I’ve been following this guide, which led me to these errors. (Im mostly using it as a way to experiment with and mess around with to understand better how OF works)
I bet your player.h has a constructor defined but not in your cpp file similar to the previous issues. Can you please check the h file from the completed code where the constructor is not there.
Maybe the chapter code is not up to date ? You might want to compare and see if there are differences.
I took the Player and playercpp files from the completed code and pasted them into mine, and I believe what you just said above is the solution to the issue.
This is the sweetest blank box I’ve ever seen in my entire life! (its not loading the image for player, but at least it compiles! Should be an easy fix of directory issues)