Wrong returns from a loop
#1

Alright so seems I am doing something wrong that I cant seem to find

So this is the code
pawn Code:
new sqlID = gateEmptyValid();
    if(sqlID == -1) return SendClientMessage(playerid,COLOR_RED,"Server cannot handle any more gates at the moment");

And this is the gateEmptyValid
pawn Code:
stock gateEmptyValid() {
    for(new i=0; i < MAX_GATES; i++) {
        if(gateInfo[i][gValid] != 1 && gateInfo[i][gID] != 0) {
            return i;
        }
    }
    return -1;
}
What should it do? Return ID of a slot where we can create a gate, but it seems it always returns -1

These are the cases in which it should return -1 instead of the actual id ID
  • If gate is valid (valid == 1)
  • If gate is ID 0

EDIT: The problem is, it always returns -1



EDIT V2:

Resolved, It was a synthax problem. I used
pawn Code:
if(gateInfo[i][gValid] != 1 && gateInfo[i][gID] != 0)
Instead of
pawn Code:
if(gateInfo[i][gValid] != 1 && i != 0)
Reply
#2

debug your function with printf ,display the values of variables needed to be evaluated to be true in the loop.That will help in fixing the code.
Reply
#3

Quote:
Originally Posted by Sreyas
View Post
debug your function with printf ,display the values of variables needed to be evaluated to be true in the loop.That will help in fixing the code.
Yeah, resolved it. I used gate ID instead instead of != 0. Thanks by the way
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)