You are mixing two different things in your code.
If you do this:
int playerx;
... it is called "declaring a variable". This tells the compiler that there is a variable (<-variable means a memory storage that will change during the running of the game) called playerx and that playerx is of type signed (i.e. can be positive or negative) and is 16 bits in size.
However, if you do this:
#define playerx
... it is called a "macro" and it is a totally different thing. The macro is an instruction for the "preprocessor" to do some things to the code BEFORE the compiler begins compiling. It sounds complicated but let me give you an example:
- Code: Select all
#define PLAYERMOVEMENT 5
int playerx = 0;
int playery = 0;
void play() {
if (gb.buttons.pressed(BTN_DOWN)){
playery += PLAYERMOVEMENT; // Pre-processor will replace PLAYERMOVEMENT with the value 5
};
if (gb.buttons.pressed(BTN_LEFT)){
playerx -= PLAYERMOVEMENT; // Now I will automatically have the same value here, thanks to the #define
};
}
So: macro is a "shorthand" for doing something so that you do not have to change the same value everywhere in the code. But it is not the same thing as a "variable". You need to declare a variable (int something) in order to reserve a memory space for a value that you will use and change during the game.
So in your code when you have
#define playerx
What it actually does is tells the preprocessor is that "playerx" is a macro and all references to "playerx" should be REPLACED with a blank space
So the line of code
playerx += 5;
actually becomes this after the preprocessor has done its job:
+=5;
After the preprocessor, the compiler starts its job, looks at that code and is complaining that there is no "lvalue" (left hand value) in the equation to add the 5 to.