SA-MP Forums Archive
error 001: expected token: ";", but found "-identifier-" - 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: error 001: expected token: ";", but found "-identifier-" (/showthread.php?tid=536354)



error 001: expected token: ";", but found "-identifier-" - Kyance - 09.09.2014

So, I've created an faction system, but for some reason I get this error.
If I change it to just do "while..." without checking the db, then "CreateFaction" stock doesn't work(in-game errors, stuff like "Couldn't create faction")
pawn Код:
stock FindNextSlot()
{
    new id, Query[100], DBResult:result;
    format(Query, sizeof(Query), "SELECT `ACTIVE` FROM `FACTIONS` WHERE `ID` = '%d'", id);
    result = db_query(Factions, Query);
    if(result)
    {
        do
        {
            new Field[70];
            db_get_field_assoc(result, "ACTIVE", Field, sizeof(Field));
        }
        while(FactionInfo[id][Active]) id ++; //error line
    }
    db_free_result(result);
    return id;
}
and
pawn Код:
stock CreateFaction(ownerid, name[])
{
    new DBResult:result, Query[360], factID = FindNextSlot();
   
    format(Query, sizeof(Query), "INSERT INTO `FACTIONS` (`ID`, `NAME`, `LOCKED`, `ACTIVE`, `MAXMEMBERS`, `MEMBERS`, `LEADER`, `HASLEADER`, `RANK1`, `RANK2`, `RANK3`, `RANK4`, `RANK5`) VALUES ('%d', '%s', '1', '1', '10', '1', '%s', '1', 'Trial Member', 'Member', 'Senior Member', 'Assistant', 'Leader')", factID, DB_Escape(name), DB_Escape(GetName(ownerid)));
    result = db_query(Factions, Query);
    if(result) SendClientMessage(ownerid, -1, "{64CC66}Faction successfully created!"), SendClientMessage(ownerid, -1, "{64CC66}You can use '/settings' to edit the faction info!");
    else SendClientMessage(ownerid, -1, "{FC4949}Failed to create faction, contact server owner(s).");
    db_free_result(result);
}



Re: error 001: expected token: ";", but found "-identifier-" - dusk - 09.09.2014

You're using the do-while loop wrong.

The syntax is
pawn Код:
do
{
   
}
while(some_statement); // not the semicolon at the end which you are lacking.
If you want to increment "id" each time the loop is executed, you should put in the "do" block.


Re: error 001: expected token: ";", but found "-identifier-" - Kyance - 09.09.2014

Quote:
Originally Posted by dusk
Посмотреть сообщение
You're using the do-while loop wrong.

The syntax is
pawn Код:
do
{
   
}
while(some_statement); // not the semicolon at the end which you are lacking.
If you want to increment "id" each time the loop is executed, you should put in the "do" block.
But why does this compile and works fine;
pawn Код:
stock FindNextSlot()
{
    new id;
    while(groupinfo[id][active]) id ++;
    return id;
}
*taken from a older group script which was made by TheKiller, but edited by me*
And yeah, I don't really understand while-do loops ;_;


Re: error 001: expected token: ";", but found "-identifier-" - dusk - 09.09.2014

Because that's not a do-while loop. It's just a simple while loop.
pawn Код:
while(groupInfo[id][active])
{
    id++;
}
pawn Код:
do
{
   id++;
} while(groupinfo[id][active]);
The code is very similiar. EXCEPT that the even if groupInfo[0][active] is false, the second bit of code will execute it while the first one won't.


Re: error 001: expected token: ";", but found "-identifier-" - Kyance - 09.09.2014

Meh, still doesn't work
pawn Код:
stock FindNextSlot()
{
    new id, Query[100], DBResult:result;
    format(Query, sizeof(Query), "SELECT `ACTIVE` FROM `FACTIONS` WHERE `ID` = '%d'", id);
    result = db_query(Factions, Query);
    if(result)
    {
        do
        {
            new Field[70];
            db_get_field_assoc(result, "ACTIVE", Field, sizeof(Field));
            if(FactionInfo[id][Active]) id++;
        }
        while(FactionInfo[id][Active]);
    }
    return id;
}
I still get the 'failed to create faction' message here;
pawn Код:
stock CreateFaction(ownerid, name[])
{
    new DBResult:result, Query[360], factID = FindNextSlot();
   
    format(Query, sizeof(Query), "INSERT INTO `FACTIONS` (`ID`, `NAME`, `LOCKED`, `ACTIVE`, `MAXMEMBERS`, `MEMBERS`, `LEADER`, `HASLEADER`, `RANK1`, `RANK2`, `RANK3`, `RANK4`, `RANK5`) VALUES ('%d', '%s', '1', '1', '10', '1', '%s', '1', 'Trial Member', 'Member', 'Senior Member', 'Assistant', 'Leader')", factID, DB_Escape(name), DB_Escape(GetName(ownerid)));
    result = db_query(Factions, Query);
    if(result) SendClientMessage(ownerid, -1, "{64CC66}Faction successfully created!"), SendClientMessage(ownerid, -1, "{64CC66}You can use '/settings' to edit the faction info!");
    else SendClientMessage(ownerid, -1, "{FC4949}Failed to create faction, contact server owner(s).");
    db_free_result(result);
}