• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] If statement help...

C

ChrisD

Guest
Hello there,

I wonder if anybody could advise me please.

I have this line >>> if (instance_exists(obj_base) && global.moving==1 && y<400){ <<<

But, for reasons that just stump me, this is allowing the "if" to be "True" even when "y" is more than 400.
I'm baffled as to why.

I have also tried to bracket each of the three checks, but that didn't help.

If anybody can tell me what I'm overlooking, I would be very grateful.

Thank you in advance.
 
M

Marcus12321

Guest
I can't see why that would happen with that statement. I am guessing something else is going on...

When using multiple logic statements like that, it is a good idea to use parenthesis though...

if ((instance_exists(obj_base)) && (global.moving==1) && (y<400)){

This way you know exactly how it is being evaluated.
 
C

ChrisD

Guest
Thanks for the reply.
I did try that, but it remained the same. Very odd.
 
C

CedSharp

Guest
In what object is that code located?
In what event?

Are you sure 'y' is the right 'y' you expected?
For example, if you are inside a 'with()' statement, the y is not the one of the current object,
but the one of the with()-targeted object.

The code you provided should never execute if 'y' is equal or larget than 400.
We need more information to help you.
What you are trying to do, and what you have done until now?

Sorry for all the questions, but I can't answer otherwise :)
 
C

ChrisD

Guest
Hi both of you and thank you for your replies.

Marcus12321 hit the nail on the head. Something else was going on, elsewhere.
It was not my "if" statement.
Fixed!

I feel a little stupid now for not looking further into it before posting.

Thanks again :)
 
Top