GameMaker help, condition never met

S

Sn3akyP1xel

Guest
I can't figure out what's happened here, i'm sure this was working last week.

If CamSpeed X or Y drops below 1, i need the else condition to execute.
The show_debug values in the debug window during play clearly shows the camera speeds in either axis dropping below 1 (in fractional values), but the else condition is never called.

I presume the if line is acceptable?

Code:
    if ( abs(CamSpeedX)>1 || abs(CamSpeedY)>1 ){
        CamX+=CamSpeedX;
        CamY+=CamSpeedY;
        show_debug_message("CamSpeedX = "+string(CamSpeedX) );
        show_debug_message("CamSpeedY = "+string(CamSpeedY) );
    }
    else{
        Do Stuff.
    }
 

jo-thijs

Member
I can't figure out what's happened here, i'm sure this was working last week.

If CamSpeed X or Y drops below 1, i need the else condition to execute.
The show_debug values in the debug window during play clearly shows the camera speeds in either axis dropping below 1 (in fractional values), but the else condition is never called.

I presume the if line is acceptable?

Code:
    if ( abs(CamSpeedX)>1 || abs(CamSpeedY)>1 ){
        CamX+=CamSpeedX;
        CamY+=CamSpeedY;
        show_debug_message("CamSpeedX = "+string(CamSpeedX) );
        show_debug_message("CamSpeedY = "+string(CamSpeedY) );
    }
    else{
        Do Stuff.
    }
Change || into &&.
 

Simon Gust

Member
Why not design the if-statement the way you described in this thread?
Code:
if (abs(CamSpeedX) < 1 || abs(CamSpeedY) < 1) {
       // Do Stuff.
}
else
{
       CamX += CamSpeedX;
       CamY += CamSpeedY;
       show_debug_message("CamSpeedX = "+string(CamSpeedX) );
       show_debug_message("CamSpeedY = "+string(CamSpeedY) );

}
The reason your code doesn't work is because the opposite of
Code:
if (flag || flag)
is
Code:
if (!flag && !flag)
You are probably going to end up scratching the statement anyway. Because now, you have to move the camera in both ways to move it at all.
 
S

Sn3akyP1xel

Guest
I thought my If was simply asking:
if either of the absolute values are below 1 then continue, else do stuff.

I need to understand this. Is it because I didn't isolate the two axis during the OR query?
so, would bracketing around both the absolutes have solved the problem also ?


Thanks all for the solution, much appreciated. I need to understand this, as I still see the original query as acceptable code and clearly it isn't.


Edit - scratch that, it's clicked !
 
Top