Im sorry to post about another error, I am new to c++. My errors this time are Error 1 error C2143: syntax error : missing ';' before '*'
Error 2 error C4430: missing type specifier - int assumed.
Error 3 error C2065: 'TOTAL_TILES' : undeclared identifier
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I do have literally 294 errors but I figure its only about 20-30 errors causing all of the other errors.
anyway here is the code. note that I moved extern Tile *tiles[TOTAL_TILES]; because it seemed more suited there.
// main surfaces
// the screen surface
SDL_Surface* surface_screen;
// the surface for the player
///////////////varibles///////////////////////
//
// if this is off then the game quits //
bool running = true; //
//
// the width and height of the level //
// will need to be changed so that //
// the world is one continuios map //
const int level_width = 1000; //
const int level_height = 1000; //
//
// the screens dimensions //
const int screen_width = 960; //
const int screen_height = 960; //
const int screen_bbp = 32; //
//
// the frames per second regulator //
const int frames_per_Second = 20; //
//////////////varibles end////////////////////
// the camera
SDL_Rect camera = {0, 0, screen_width, screen_height};
//if sdl finds an event
if(SDL_PollEvent(&event))
{
x_quit();
// checks if player has moved
// if player has moved then it moves the sprite
// at the draw sprite function
mainplayer.handle_input();
}
//loads the graphics
load_graphics();
// draws the background so that the sprites can erase properly
spr_background();
//loads the test map
// place holder [load_map("maps\\map.map");]
mainplayer.move(tiles);
//show tiles
for(int t = 0; t < TOTAL_TILES; t++){
tiles[t]->show();
}
// game start
// draws the players surface
mainplayer.show();
// flips the screen and draws all new graphics
SDL_Flip(surface_screen);
}
SDL_Quit();
return 0;
}
and main.h #pragma once
#include "SDL.h"
#include "tile_load.h"
//varibles
extern bool running;
extern const int level_width;
extern const int level_height;
extern const int screen_width;
extern const int screen_height;
extern const int screen_bbp;
extern Tile *tiles[TOTAL_TILES];
// camera
extern SDL_Rect camera;
//events
extern SDL_Event event;
// surfaces
extern SDL_Surface* surface_screen;
And you may think that I haven't even looked up my errors, but i spent 2 hours last night googling my errors.
if anymore information or files is required please ask. thanks for your time.
You will have to excuse me if I am mistaken here (I have not coded C++ in a good few months, been stuck on java lately), but from what I'm seeing here I can say the following:
First off, howcome you're using the "extern" keyword on all your variables? Is this necessary? Second, what is "Tile"? This is an object you have created, right? Well, you probably need to declare that on the heap, using the "new" keyword. Third, your use of "TOTAL_TILES" - as the error states... what is this? The all-caps imply that this is a constant - but where is it declared? This needs to have a value or must at least be assigned a type (an integer, basically).
Also... on another note: I am assuming that the array of tiles are all your ingame tiles, yes? Well, using a 1-dimensional array for that means you'll have one long line of tiles , unless you have algorithms of some kind to rearrange these graphically. I would suggest a 2 or 3 dimensional array instead, depending on what you're trying to do there.
Since char is recognized internally, this is not the error.
Therefore either SDL_Surface is not defined or Tile is not defined.
Since you just moved “tiles”, that would be a likely candidate, especially considering that TOTAL_TILES is also not defined. Include the proper headers.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
[color=#660066]Error[color=#000000] [color=#006666]1[color=#000000] error C2143[color=#666600]:[color=#000000] syntax error [color=#666600]:[color=#000000] missing [color=#008800]';'[color=#000000] before [color=#008800]'*'[color=#000000]
[color=#660066]Error[color=#000000] [color=#006666]2[color=#000000] error C4430[color=#666600]:[color=#000000] missing type specifier [color=#666600]-[color=#000000] [color=#000088]int[color=#000000] assumed[color=#666600].[color=#000000]
[color=#660066]Error[color=#000000] [color=#006666]3[color=#000000] error C2065[color=#666600]:[color=#000000] [color=#008800]'TOTAL_TILES'[color=#000000] [color=#666600]:[color=#000000] undeclared identifier
[color=#660066]Error[color=#000000] [color=#006666]4[color=#000000] error C4430[color=#666600]:[color=#000000] missing type specifier [color=#666600]-[color=#000000] [color=#000088]int[color=#000000] assumed[color=#666600].[color=#000000] [color=#660066]Note[color=#666600]:[color=#000000] C[color=#666600]++[color=#000000] does [color=#000088]not[color=#000000] support [color=#000088]default[color=#666600]-[color=#000088]int[color=#000000]
In your actual error messages (not these modified ones) you will know which line it is on.
Error 1 is pretty obvious -- you are missing a semicolon somewhere. Look at the line before the line in the error. You might have missed a semicolon, or a parenthesis, or some other symbol. We'd need to know exactly which line it is, and the line before it, to help with that.
Error 2 is probably caused by error 1.
Error 3 (the TOTAL_TILES error) is likely from your main.h, but again check the actual line number. You are using it before it is declared. You wrote that you moved it because "it is more suited there", but if it causes compiler errors than obviously it is not. You would probably be fine with a simple pointer there since it is an extern declaration, but it depends entirely on what you are trying to do with it.
Error 1 is pretty obvious -- you are missing a semicolon somewhere. Look at the line before the line in the error. You might have missed a semicolon, or a parenthesis, or some other symbol. We'd need to know exactly which line it is, and the line before it, to help with that.
I would normally not say anything but the original poster may end up searching a long time for this.
In this case it actually means Tile is not a defined type. The error is regarding Tile *tiles[TOTAL_TILES]; or extern Tile *tiles[TOTAL_TILES];.
When he includes the proper file, all errors will go away.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
First off, howcome you're using the "extern" keyword on all your variables?[/quote]
Stupid of me sorry i didn't realize that i had the externs there. I got rid of the declaration in main.cpp
and declared them in main.h
Second, what is "Tile"? This is an object you have created, right? Well, you probably need to declare that on the heap, using the "new" keyword.[/quote]
How would I do this.
Third, your use of "TOTAL_TILES" - as the error states... what is this? The all-caps imply that this is a constant - but where is it declared? This needs to have a value or must at least be assigned a type (an integer, basically).
It has been declared and the proper header has been used, I'll show you the code where it's been declared
Also... on another note: I am assuming that the array of tiles are all your ingame tiles, yes? Well, using a 1-dimensional array for that means you'll have one long line of tiles , unless you have algorithms of some kind to rearrange these graphically. I would suggest a 2 or 3 dimensional array instead, depending on what you're trying to do there.[/quote]
Yes i do use a kind of algorithm for that.
bool set_tiles(Tile *tiles[]){
//the tiles offsets
int x = 0, y = 0;
// open the map
std::ifstream map("maps//map.map");
//if the map couldnt be loaded
if(map == NULL){
return false;
}
//initialize the tiles
for(int t = 0; t < TOTAL_TILES; t++){
//what kind of tile will be made
int tiletype = -1;
//read tile from map
map >> tiletype;
//if there was a problem reading the map
if(map.fail() == true){
//stop laoding map
map.close();
return false;
}
//if the number is a valid tile
if((tiletype >= 0 ) && (tiletype < TILE_SPRITES)){
tiles[t] = new Tile(x, y, tiletype);
}
// if we dont recognize the tile type
else{
//stop loading map
map.close();
return false;
}
//move to th next tile spot
x += TILE_WIDTH;
//if we've gone to far
if( x >= level_width){
//move back
x = 0;
//move to the next row
y += TILE_HEIGHT;
}
// clsoe file
map.close();
//if the map loaded
return true;
}
}
YogurtEmperor
I can't believe your compiler does not print the lines of the errors. You need to find a new compiler.[/quote]
I use Microsoft visual 2010 express and yes it does display lines I just accidentally cut them off, My bad there. Here are they error codes
with the line numbers.
Error: Line: column:
Error 1 error C2143: syntax error : missing ';' before '*' 20 1
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 20 1
Error 3 error C2065: 'TOTAL_TILES' : undeclared identifier 20 1
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 20 1
Line 20 in what file?
There is nothing on line 20 in either file.
Error 2 error C4430: missing type specifier - int assumed.[/quote]
This error means you did not declare something.
Error #1 means an unknown identifier precedes a * (pointer).
The error is either Tile *tiles[TOTAL_TILES]; or extern Tile *tiles[TOTAL_TILES];.
Specifically, Tile has not been defined because a header file is missing.
When you post compiler errors, always post the line numbers and the file names.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Error 1 error C2143: syntax error : missing ';' before '*' main.h 21 1
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int main.h 21 1
Error 3 error C2065: 'TOTAL_TILES' : undeclared identifier main.h 21 1
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int main.h 21 1