|
-
Nov 10th, 2002, 12:24 PM
#1
Thread Starter
Frenzied Member
if statement.....again...
I can't get this if statement to work....I know it something with the {}.....
PHP Code:
if(ball.x > SCREEN_WIDTH - ball.width )
{
xangle = -xangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
if(ball.x <0)
{
xangle = xangle;
yangle = yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
if (ball.y < 0)
{
xangle = xangle;
yangle = yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
if(ball.x > SCREEN_HEIGHT)
{
xangle = -xangle;
yangle = -yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
-
Nov 10th, 2002, 12:45 PM
#2
Junior Member
What doesn't work (i'd like to know what to look for)?
-
Nov 10th, 2002, 12:52 PM
#3
Member
Which if statement there are several? If it is the following if statement:
Code:
if(ball.x > SCREEN_WIDTH - ball.width )
you may want to try
Code:
if(ball.x > (SCREEN_WIDTH - ball.width) )
-
Nov 10th, 2002, 01:13 PM
#4
Thread Starter
Frenzied Member
the problem is that is doesn't run any of them....
-
Nov 10th, 2002, 01:27 PM
#5
Member
I know it something with the {}.....
Your braces look fine to me, have you tried printing the value of ball.x before each if statement to check its contents? Have you also checked to see that it is not executing the code within the braces by placing a print statement within each of the if braces for example:
Code:
if(ball.x <0)
{
print "ball.x is less than zero.";
xangle = xangle;
yangle = yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
-
Nov 10th, 2002, 07:35 PM
#6
if
Move_BOB(&ball)
changes the value of ball.x then more than one of your if statements may be executed. I would set them up as
PHP Code:
if(ball.x > SCREEN_WIDTH - ball.width )
{
xangle = -xangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
else if (ball.x <0)
{
xangle = xangle;
yangle = yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
else if (ball.y < 0)
{
xangle = xangle;
yangle = yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
else if(ball.x > SCREEN_HEIGHT)
{
xangle = -xangle;
yangle = -yangle;
ball.xv = xangle;
ball.yv = yangle;
Move_BOB(&ball);
}
but that may not be it.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Nov 10th, 2002, 08:38 PM
#7
Member
Sunburnt, makes a very good point. I can not see anything wrong with the code I think it is more than likely the structuring of it and how you wish it to operate. This is partly why I suggested that you place print statements into the code as this would give you more of an understanding about what routes the code is currently taking and why.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|