Why will this if statement not work?

Started by
24 comments, last by mikeman 17 years, 10 months ago
I can't get debug to work in dev cpp
It says my project doesn't have debug information, do you want to add? I click yes, and then go to debug, and it goes through the same thing.
Advertisement
You're right, Pulpfist. But it still errors out.
Post the rest of the code. The function looks OK, but we can't have any idea why it doesn't do what you want it to do without knowing how you use it in the context of the program.
Hey heres an idea. You changed your x from the original code to y correct. So your code looks something like this now:

bool block::atBottom(){    if(y <= -0.9)    {        moveable = false;        return true;    }    else        return false;}


By the looks of the function it looks like your trying to find out if the block is at the bottom. So why are you using <= if the blocks are falling. And if your dealing with 3D here then -0.9 is just below the origin right. So your going to have to have your blocks below the origin and have them travel up the y-axis. This might solve the problem its how i would do it:

bool block::atBottom(){    if(y >= -0.9) // If the y coordinate is below -0.9    {        moveable = false;        return true;    }    else    {        return false;    }}


Just make sure the blocks start above -0.9 and that they are falling downwards. Good-luck and i hope i helped out a little.
Quote:Original post by Niddles
I can't get debug to work in dev cpp
It says my project doesn't have debug information, do you want to add? I click yes, and then go to debug, and it goes through the same thing.

You need to make sure that you are building your project in 'debug' mode. If that fails, try searching around the build options to see if there is an option to include debug information in your project.

Concerning your function: -

bool block::atBottom(){    if(x <= -0.9)    {        moveable = false;        return true;    }    else        return false;}


would you not want to reset the 'moveable' variable if x > -0.9?

AKA

bool block::atBottom(){    if(x <= -0.9)    {        moveable = false;        return true;    }    else    {        moveable = true;        return false;    }}
I would say drop this
if(x <
At what y value do the blocks start falling, and what is the y value of a block at the bottom?
|          | <--- start value == ?|          ||          ||          ||          ||          ||          ||          ||          ||          | <--- bottom value == ?+----------+

Without knowing that we can only guess about the semantics of your code.

BTW your (apparently incorrect) code can be abbreviated to one line (with the same incorrect behaviour):
bool block::atBottom(){    return (!(moveable = (!(x <= -0.9))));}

Why not use the 'f'-postfix?
(From an example above):
flaot a = 0.9/3.0;

if(a <
float a = 0.9/3.0;if(a <= 0.3f){//should execute}
bool block::isAtBottom() { return (x <= -0.9f); }


you should separate logic from conditions, moveable = false; is more something what results when block is at bottom, rather not the condition.

double and floating point are different. I wouldn't be surprized if your first try would work in another compiler thought.
~ person who has nothing to say feels itself naked in enviroment where nonsense is hard to camouflage into the nonexistent myriad of noises. ~

This topic is closed to new replies.

Advertisement