Why doesn't the following code find ScanY < 0
true in the (or) || check?
It recognises it in the if (ScanY < 0) check!! this has been bugging me.. I must be missing something
AGS 3.3.3
while(nextY + StartY > EndY)
{
if (!TypeHit)
nextY --;
else if (TypeHit || (ScanY > Room.Height) || (ScanY < 0))
nextY = EndY - StartY;
//write it like this and it works:
if (ScanY < 0)
nextY = EndY - StartY;
}
Well, one thing, the "if (TypeHit" part is redundant. Your first if statement checks to see if TypeHit is not true. Anything in the else clause will only be executed if TypeHit is true. So you could rewrite your current code as:
while(nextY + StartY > EndY)
{
if (!TypeHit)
nextY --;
else if ((ScanY > Room.Height) || (ScanY < 0))
nextY = EndY - StartY;
}
And it would mean exactly that same thing. I would guess that it's not running the second nextY statement because TypeHit is always false. You could verify what's happening by inserting some logging. I like to use SayBackground for this purpose:
while(nextY + StartY > EndY)
{
if (!TypeHit)
{
cEgo.SayBackground("If part");
nextY --;
}
else
{
cEgo.SayBackground("Else part");
if ((ScanY > Room.Height) || (ScanY < 0))
{
cEgo.SayBackground("ScanY > Room.Height || ScanY < 0");
nextY = EndY - StartY;
}
}
}
Even so, I'm fairly confident that if you're not seeing that condition evaluated, it's probably the "else" part that's to blame. Did you really mean that else statement or did you perhaps mean this?
while(nextY + StartY > EndY)
{
if (!TypeHit)
nextY --;
if (TypeHit || (ScanY > Room.Height) || (ScanY < 0))
nextY = EndY - StartY;
}
Hope this helps.
Just a general remark: something like ScanY < 0 is evaluated to true or false correctly. Always. No matter what.
If you find yourself thinking that AGS gets it wrong, you are mistaken. Always. No matter what.
No no Khris, I thought I was using the 'or' || qualifier[?] wrong somehow...
Gurok, thanks I was a bonehead, maybe a little tired :-[ Removing 'else' fixed it, typehit was false but y<0 was true! D'oh!! Logic (wtf)
Pulling the redundant junk out does make the error jump out a bit better, I'll have to remember that.