Wrong returns from a loop - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Wrong returns from a loop (
/showthread.php?tid=622216)
Wrong returns from a loop -
TwinkiDaBoss - 20.11.2016
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)
Re: Wrong returns from a loop -
SyS - 20.11.2016
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.
Re: Wrong returns from a loop -
TwinkiDaBoss - 20.11.2016
Quote:
Originally Posted by Sreyas
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