Something weird I found
#1

Hi guys, when I was making this small piece of code, I thought I was programming in Lua so I put this down:

pawn Код:
COMMAND:admins(playerid, params[])
{
    new AdminCount = 0;
    foreach(Player, i) if pData[i][AdminLevel] >= 1 then AdminCount++;
}
As you see I put in the statement 'then', now that came up with a funny error.

Код:
C:\Documents and Settings\Elliot\My Documents\Game Stuff\San Andreas Flight Club\Server\gamemodes\flight.pwn(426) : error 001: expected token: "*then", but found "-identifier-"
C:\Documents and Settings\Elliot\My Documents\Game Stuff\San Andreas Flight Club\Server\gamemodes\flight.pwn(426) : error 017: undefined symbol "then"
As you can see the expected token is '*then', and so I put that into my command.

pawn Код:
COMMAND:admins(playerid, params[])
{
    new AdminCount = 0;
    foreach(Player, i) if pData[i][AdminLevel] >= 1 *then AdminCount++;
}
And it came up with no errors. And the code works.

Now, am I a total noob for not ever knowing about this? Or does no one ever use it? Because I haven't seen this being used in many scripts. And were any of you aware of this?
Reply
#2

oh sorry didn't read whole topic
Reply
#3

Quote:
Originally Posted by mincer1667
Посмотреть сообщение
pawn Код:
COMMAND:admins(playerid, params[])
{
    new AdminCount = 0;
    foreach(Player, i) { if(pData[i][AdminLevel] >= 1) AdminCount++; }
}
try that
Did you even READ the topic? I doubt so, I'm not asking for help, I just want to discuss about this '*then' statement.
Reply
#4

Your whole syntax is incorrect, this is why you received the error. "then" isn't a keyword in PAWN, and you also need to wrap your conditional statements within parenthesis.
Reply
#5

Quote:
Originally Posted by Disturn
Посмотреть сообщение
Your whole syntax is incorrect, this is why you received the error. "then" isn't a keyword in PAWN, and you also need to wrap your conditional statements within parenthesis.
There is nothing wrong with this code as it has been working perfectly.

And by my syntax being incorrect do you mean this line?

pawn Код:
foreach(Player, i) if pData[i][AdminLevel] >= 1 *then AdminCount++;
Because I put that in there to make it look neat, because I don't want two foreach statements in the command drooping down. Here is the final command:

pawn Код:
COMMAND:admins(playerid, params[])
{
    new AdminCount = 0;
    foreach(Player, i) if pData[i][AdminLevel] >= 1 *then AdminCount++;
    if(AdminCount == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "There are no admins online right now!");
    }
    else
    {
        new Msg[128];
        format(Msg, sizeof(Msg), "Current online admins (%d):", AdminCount);
        SendClientMessage(playerid, COLOR_YELLOW, Msg);
        foreach(Player, i)
        {
            if(pData[i][AdminLevel] >= 1)
            {
                new Rank[20];
                switch(pData[i][AdminLevel])
                {
                    case 1: Rank = "Helper";
                    case 2: Rank = "Moderator";
                    case 3: Rank = "Administrator";
                    case 4: Rank = "Head Administrator";
                    case 5: Rank = "Co-Owner";
                    case 6: Rank = "Owner";
                }
                format(Msg, sizeof(Msg), "{80FF00}%s({FFFFFF}%i{80FF00}){FFFFFF} - Rank: %s - Level %i", ReturnName(i), i, Rank, pData[i][AdminLevel]);
                SendClientMessage(playerid, COLOR_GREEN, Msg);
            }
        }
    }
    return 1;
}
Reply
#6

Errrmm... You tested it in practical use? BTW I kind of knew about this. When I first started learning PAWN I did the exact same thing by following the error lines and came up with the same thing, but I never tried it because I then found the wiki.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)