🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Is Visual C++ having a hard time reading my code?

Started by
10 comments, last by GameDev.net 19 years, 10 months ago
It keeps on saying c:\Documents and Settings\Randle\Desktop\randyx's stuff\PROJECTS\move image\mo.cpp(80): error C2065: 'screen' : undeclared identifier This is starting to bug me. The Eerror is on the line SDL_Flip (Screen);.Heres my code{I erased semicolons):
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include "SDL.h"

void run()
 {
	 Uint32 dt;
	 Uint32 move;
	 move = SDL_GetTicks();
	 SDL_Rect dest;
      Uint32 lastframe;
	 move =  SDL_GetTicks() - move
        
		dest.x += 2 * lastframe;
	      dest.y += 2 * lastframe;
 }

int main( int argc, char* argv[] )
{
Uint32 lastframe=SDL_GetTicks();
while(true) {
  Uint32 dt=SDL_GetTicks()-lastframe;
  lastframe=SDL_GetTicks();
	Uint32 move;
  SDL_Init( SDL_INIT_VIDEO );  
 move = SDL_GetTicks()

  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;//saving for later use//
  SDL_Event b;//saving for later use//
  SDL_Event Event  //saving for later use//            
	 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" );
               
				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()
		}
	}
	  }
} 
		SDL_Flip( screen );
     atexit(SDL_Quit);
  return 0;
		}
  


I reinstaled it,but it did'nt help
Advertisement
Declare the screen pointer outside of the while loop. It looses it's scope.

Lizard

EDIT: And don't take away semicolons from you posted code in the future =)
You mustn't call SDL_Init(SDL_INIT_VIDEO) multiple times like that. Generally once per program is enough. The same goes for SDL_SetVideoMode. You will need to really think about your code because I don't think that will do anything like what you want it to.
error C2501: 'atexit' : missing storage-class or type specifiers
error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(void)' to 'int'
: error C2365: 'atexit' : redefinition; previous definition was a 'function'
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : '}'
missing ';' before '}'
error C2059: syntax error : '}'
grrrrrrr!!!!!!What going on?
You need to include a header file for atexit. The rest is probably down to your missing semi-colons and so on. Remember, terminate every statement with a semi-colon.
I certainly am...also, looks like you have to many }'s

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

I didnt know you needed a header file for atexit...Wich one?
[google]: "atexit"

http://www.google.com/search?q=atexit

[EDIT: and just out of curiosity how do you ever plan to have your program execute the code after the 2nd while(true) loop? you never terminate the loop, so none of the code after it will ever be called]

-me
It givesme linking error that I can't read.
msvcrt.lib(MSVCR71.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/move image.exe : fatal error LNK1169: one or more multiply defined symbolS
Anyone know of a tutorial on reading errors?
thanks a linking error. im assuming your using VS.net by the looks of how you included your libraries. try switching the "code generation" in to "Multi-threaded DLL".

click view, then solution explorer

right click the project name, go to properties

click the C++ folder

click Code Generation

in the Runtime Library field, set it to Multi-Threaded DLL (/MD). it might also work using Multi threaded debug DLL.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement