something wrong with this function?

Started by
9 comments, last by Endurion 18 years ago



void CheckBounds()

  {


if (xpos >= LEVEL_WIDTH)
{
        {xpos = LEVEL_WIDTH - ship_WIDTH;}

    if (ypso >= LEVEL_HEIGHT)

 	{ypos = LEVEL_HEIGHT - ship_HEIGHT;}
}
}



I can't get it to compile but I don't see anything wrong with it. The error says: expected primary-expression before '=' token. Thanks for any tips.
Advertisement
Is 'ypso' a typo in the line below?

if (ypso >= LEVEL_HEIGHT)


Doolwind
Where are the variables declared ?
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
It was but I changed it. The variables are:

int xpos = 0, ypos = 0;

and the defines are:

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP = 32
#define LEVEL_WIDTH = 1280
#define LEVEL_HEIGHT = 960
#define ship_WIDTH = 84
#define ship_HEIGHT = 63
Quote:Original post by SKATIN_HARD
It was but I changed it. The variables are:

int xpos = 0, ypos = 0;

and the defines are:

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP = 32
#define LEVEL_WIDTH = 1280
#define LEVEL_HEIGHT = 960
#define ship_WIDTH = 84
#define ship_HEIGHT = 63


You should not put the = in those macros. Also, it is generally considered better practice to use const instead of making macros for constants.
First, formatting your code in a way such as this would make it more readable. Second, you have a scope in there that does not really make sense.

Third, there's no = in macros.

void CheckBounds(){	if (xpos >= LEVEL_WIDTH)	{        	xpos = LEVEL_WIDTH - ship_WIDTH;				if (ypso >= LEVEL_HEIGHT) 		{			ypos = LEVEL_HEIGHT - ship_HEIGHT;		}	}}
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
Took out the "=" and still got the same error. I just want to limit the sprite from going off the screen.
Quote:Original post by SKATIN_HARD
Took out the "=" and still got the same error. I just want to limit the sprite from going off the screen.


Did you take all of them out?
void CheckBounds()
{
if (xpos >= LEVEL_WIDTH)
xpos = LEVEL_WIDTH - ship_WIDTH;

if (ypos >= LEVEL_HEIGHT)
ypos = LEVEL_HEIGHT - ship_HEIGHT;
}
-----------------------------Language: C++API: Win32, DirectXCompiler: VC++ 2003
Thanks Simon but I tried that and got the same error.

This topic is closed to new replies.

Advertisement