What does this error mean?

Started by
14 comments, last by darookie 19 years, 6 months ago
Quote:Original post by Unwise owl
My god, is that indentation caused by the transfer from code to forums or do you acually write like that? Putting the semicolons before the following statements is NOT the standard approach, eg. ";dtime = elapsed_time / 1000".


The code used a mix of tabs and spaces to indent. The OP's editor probably used a different tab width than your web browser. I fixed things up.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Sorry about the semi-colons if I dont put them before insteead of after I get an error.Um after the int mai on the next line I get an error that says:SDL_main' : local function definitions are illegal. I dont get why it's on a "{".CODE UPDATE

error C2676: binary '+' : 'SDL_Rect' does not define this operator or a conversion to a type acceptable to the predefined operator
code update
Since I can't edit my originaal post i'm doing it here

ifdef WIN32#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")#endif#include "SDL.h"#include <stdlib.h>;void run(){   float start_time;   start_time = SDL_GetTicks();   int i;   i=5   //  loop    while(i=5)   {       float dtime;      float end_time;      float elapsed_time;      float vvlosity;      vvlosity = 5;      SDL_Rect dest;        dest.x = 2;        dest.y = 2;        end_time = SDL_GetTicks();          // now we have how much time passed in the last loop       elapsed_time = end_time - start_time;        // here's the new code, dtime must be a floating point number       dtime = elapsed_time / 1000;      // Get new start time       start_time = SDL_GetTicks();      dest.x=dest.x + dtime *vvlosity;     dest.y = dest.y + dtime *vvlosity;     // end loop    }   int main( int argc, char* argv[] )   {      //initialize systems  SDL_Init ( SDL_INIT_VIDEO ) ;  //set our at exit function  atexit ( SDL_Quit ) ;      SDL_Surface * screen = SDL_SetVideoMode( 800,600, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );        SDL_Surface * img = SDL_LoadBMP( "filename.bmp" );         SDL_Rect dest;        dest.x = 2;        dest.y = 2;        SDL_Event event;      SDL_Event a;      SDL_Event b;      SDL_Event Event;      SDL_Rect coord;      coord.x = 200;      coord.y = 500;      SDL_Surface * tdisplay = SDL_SetVideoMode( 800,600,24,SDL_ANYFORMAT|SDL_DOUBLEBUF );      SDL_Surface * imi = SDL_LoadBMP( "ad.bmp" );      SDL_Surface * bckg = SDL_LoadBMP ( "bg.bmp" );                        Uint32 now;      ;      while(true)       {		         SDL_BlitSurface(img,NULL,screen, &dest);		         SDL_PollEvent(&event);		         if(event.type == SDL_MOUSEBUTTONDOWN)          {			            if(event.button.button == SDL_BUTTON_LEFT)             {	              		SDL_GetMouseState(&coord.x, &coord.y);	               SDL_BlitSurface(imi,NULL,tdisplay,&coord);		               SDL_Flip(tdisplay);               ;            }         }	      }      if(event.type == SDL_QUIT)       {          return 0;       }        SDL_Event up;      while(true)      {         if(up.type == SDL_KEYDOWN)         {            if(up.key.keysym.sym == SDLK_SPACE)            {               run();            }         }      }   }   atexit(SDL_Quit);   return run();   ;}




[Edited by - MPG on October 1, 2004 10:34:27 AM]
[edit: never mind]
For heaven's sake - get a decent editor!
Your run() function misses the closing '}'.
Also why are you spreading completely useless semicolons all over your code?

#ifdef WIN32#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")#endif#include "SDL.h"#include <stdlib.h>;  // <--- what is this semicolon for???void run(){   float start_time;   start_time = SDL_GetTicks();   //  loop    while(true) // <--- ????   {       float dtime;      float end_time;      float elapsed_time;      float vvlosity;      vvlosity = 5;      SDL_Rect dest;        dest.x = 2;        dest.y = 2;        end_time = SDL_GetTicks();          // now we have how much time passed in the last loop       elapsed_time = end_time - start_time;        // here's the new code, dtime must be a floating point number       dtime = elapsed_time / 1000;      // Get new start time       start_time = SDL_GetTicks();       dest=dest + dtime *vvlosity;     // end loop    }} // <--- end run() function   int main( int argc, char* argv[] )   {      ; // <--- ????             // AFAIK you need to call SDL_Init() first...      SDL_Surface * screen = SDL_SetVideoMode( 800,600, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );        SDL_Surface * img = SDL_LoadBMP( "filename.bmp" );         SDL_Rect dest;        dest.x = 2;        dest.y = 2;        SDL_Event event;      SDL_Event a;      SDL_Event b;      SDL_Event Event;      SDL_Rect coord;      coord.x = 200;      coord.y = 500;      // I didn't use SDL for years, but this is certainly wrong!      // Why do you chenge the video mode again?      SDL_Surface * tdisplay = SDL_SetVideoMode( 800,600,24,SDL_ANYFORMAT|SDL_DOUBLEBUF );      SDL_Surface * imi = SDL_LoadBMP( "ad.bmp" );      SDL_Surface * bckg = SDL_LoadBMP ( "bg.bmp" );                     SDL_Flip( screen );      Uint32 now;      ; // <--- ????      while(true)  // <--- ????      {		         SDL_BlitSurface(img,NULL,screen, &dest);		         SDL_PollEvent(&event);		         if(event.type == SDL_MOUSEBUTTONDOWN)          {			            if(event.button.button == SDL_BUTTON_LEFT)             {				               SDL_BlitSurface(imi,NULL,tdisplay,&coord);		               SDL_Flip(tdisplay);               ; // <--- ????            }         }	      }      if(event.type == SDL_QUIT) // <--- ????      {          return 0;       }        SDL_Event up;      while(true)  // <--- ????      {         if(up.type == SDL_KEYDOWN)         {            if(up.key.keysym.sym == SDLK_SPACE)            {               run();            }         }      }   }   atexit(SDL_Quit);  // <--- ???? you already did that...   return run();   ;  // <--- ????}


No offense, but do you even have the slightest idea of what your code does? You have so many infinitive loops that just make no sense at all (marked by ????). And the program doesn't have any reasonable structure (ie. init SDL -> load surfaces -> event-loop -> exit).

Sorry to say that, but it seems you have absolutely no clue of what you are doing. Try to start from scratch by just writing a clean event loop.

[Edited by - darookie on October 1, 2004 11:59:43 AM]
Ok I pput what neede to be in a into one big loop. In my run function would i still need a loop?


EDIT: darookie, I don't know how thoose semi-colons got there ut,there not in my editor.
Quote:Original post by MPG
Ok I pput what neede to be in a into one big loop. In my run function would i still need a loop?

I'll post a working version in a couple of minutes. So stay tuned [wink].
Quote:
EDIT: darookie, I don't know how thoose semi-colons got there ut,there not in my editor.

Maybe some copy 'n paste issue... Not your fault then obviously.

PS: Sorry for bitching about your code, it just looked too confusing.
First of all THANKS MPG!
Since I didn't have SDL installed on my Windows box, I quickly setup my laptop for SDL (it runs Linux). Now I seriously consider porting an old game of mine from DOS to Linux using SDL [smile].

Oh, and here's some code for you:

#ifdef WIN32#  pragma comment(lib, "SDL.lib")#  pragma comment(lib, "SDLmain.lib")#endif#include <SDL/SDL.h> // <-- you might need to change that into #include "sdl.h"#include <cstdio>#include <cstdlib> // window setup - change to 800 and 600 if you likestatic const int WINDOW_WIDTH = 640;static const int WINDOW_HEIGHT= 480;// Initialise SDL// - returns boolean result: true if succeeded false//   otherwisebool Initialise() {	if (SDL_Init(SDL_INIT_VIDEO) < 0) {		fprintf(stderr, "Could not initialize SDL: %s\n", 			SDL_GetError());		return false;	}	atexit(SDL_Quit);	return true;}// Setup SDL video mode// - returns Screen surface or NULL pointer on failureSDL_Surface *SetupVideoMode() {	SDL_Surface *screen = 0;	screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 16, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_DOUBLEBUF);	if( !screen ) {		fprintf(stderr, "Couldn't create a surface: %s\n",			SDL_GetError());	}	return screen;} // Main program entry pointint main(int argc, char *argv[]) {	// step 1) - initialisation	if (!Initialise()) {		return -1;	}	// step 2) - setup video mode	SDL_Surface *screen = SetupVideoMode();	if (!screen) {		return -2;	}	// step 3) - load resources	SDL_Surface * background;     // this is my background image, it matches the window size	SDL_Surface * sprite;         // some small sprite image		background = SDL_LoadBMP("bkgnd.bmp");	sprites = SDL_LoadBMP("sprites.bmp");	if (!background || !sprites) {		fprintf(stderr, "Failed to load image: %s\n",		SDL_GetError());		return -3;	}	        // the position of the sprite on screen	SDL_Rect      spritePosition;	spritePosition.x = 0;	spritePosition.y = WINDOW_HEIGHT / 2;  // place it somewhere in the middle of the window		// step 4) - event loop	SDL_Event event;	bool exitRequested = false;  // this flag terminates the loop when set to "true"		while (!exitRequested) {		// draw background and sprite		SDL_BlitSurface(background, 0, screen, 0);		SDL_BlitSurface(sprites, 0, screen, &spritePosition);		                // check for events		while (SDL_PollEvent(&event)) {			switch (event.type) {			case SDL_QUIT:				exitRequested = true;				break;			case SDL_KEYDOWN:				switch (event.key.keysym.sym) {                                // escape key exits				case SDLK_ESCAPE:					exitRequested = true;					break;                                // hitting left cursor moves the prite left				case SDLK_LEFT:					if (spritePosition.x > 0)						spritePosition.x += 4;					break;                                // same as above but in the other direction				case SDLK_RIGHT:					if (spritePosition.x < WINDOW_WIDTH-60)						spritePosition.x += 4;					break;				default:					break;				}				break;			}		}                // update screen content		SDL_Flip(screen);	}		return 0;}


Have fun with that,
Pat.

This topic is closed to new replies.

Advertisement