SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/11/2016, 12:56 AM   #1
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 795
Reputation: 54
Default Wrong returns from a loop

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)
TwinkiDaBoss is offline   Reply With Quote
Old 20/11/2016, 01:02 AM   #2
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,939
Reputation: 504
Default Re: Wrong returns from a loop

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.
SyS is offline   Reply With Quote
Old 20/11/2016, 01:21 AM   #3
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 795
Reputation: 54
Default Re: Wrong returns from a loop

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
TwinkiDaBoss is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateDynamicPickup returns wrong id sagosagi1 Scripting Help 3 06/05/2014 03:11 AM
This returns the wrong timestamp. Dokins Scripting Help 1 02/04/2012 06:09 PM
This returns the Chat to clear. What's wrong? iGetty Scripting Help 8 14/12/2011 03:40 PM
Returns wrong Unknown123 Help Archive 2 24/06/2011 04:51 AM
GetPlayerWeaponData ammo returns -1 in a loop (sometimes) Nakash Help Archive 3 17/01/2010 03:33 PM


All times are GMT. The time now is 06:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.