Skip to main content
GameDev.net gamedev.net
🔒 Locked

wierd errors

Started by hibiki_konzaki Jul 31, 2002 at 7:59 PM 0 replies 200+ views
Original Post
hibiki_konzaki
hibiki_konzaki
Ok, I''m trying to fire a bullet in a 2-d side scroller, and I''m getting 2 errors when I try to set up a RECT so I can blt a small square to the screen. C:\Program Files\Microsoft Visual Studio\MyProjects\engine\engine.cpp(447) : error C2057: expected constant expression C:\Program Files\Microsoft Visual Studio\MyProjects\engine\engine.cpp(447) : error C2466: cannot allocate an array of constant size 0 heres the code
  
	int temp = activebullets;
	int something = 5;

	if(temp == 0)
	{
		while(something >0)
		{
			Fired[something].pos_x = Homie.pos_x + 47;
			Fired[something].pos_y = Homie.pos_y + 40;
			something--;
		}
	}

	if(activebullets !=0)
	{
		DDBLTFX ddbltfx;
		DDRAW_INIT_STRUCT(ddbltfx);
		ddbltfx.dwFillColor = RGB565(254,254,254);

		while(temp > 0)
		{
			Fired[temp].MoveBullet(3);
			RECT bullet[temp] = {Fired[temp].pos_x,Fired[temp].pos_y,
				Fired[temp].pos_x +4,Fired[temp].pos_y + 4};
			if(FAILED(lpddsback->Blt(•[temp],NULL,NULL,DDBLT_WAIT | DDBLT_COLORFILL,&ddbltfx)))
				MessageBox(main_window_handle,"error","draw bullet",NULL);
			

			if(Fired[temp].Offscreen())
				activebullets--;
			
			temp--;
		}
	}
  
Fired[]s are Bullet objects. I made 5 of them, and each frame that one isn''t fired the position of each bullet is moved to that of the player (Homie object). The problem is some where in that segment of code (I think) but I don''t see whats wrong. Hopefully someone here will. Hibiki Wheres the any key?

find your element at mutedfaith.com. <º>
Laroche
Laroche
It looks like the line which declares the rect array in not using a constant expression. By constant, I mean that every time this piece of code gets called (I''m assuming it''s in a function or something) the var activebullets, and therefore temp, would be different.

You cannot allocate arrays in this fashion, unless you dynamically assign memory to it, and then delete it later on. I would give a code example, but I''ve never had a use for it (yet) so I don''t know the exact syntax..

I suppose one way to solve your problem would be to have a vector of rects. If you don''t know about vectors or the STL, I would suggest looking into them

Hope I''ve helped!
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.