invalid subscript (not an array or too many subscripts)
#1

[PAWN]
Hello I've started coding in PAWN again when I found out my script had some un fixed errors, to the life of me I don't know how to fix them.
Errors:
pawn Код:
Script.pwn(488) : error 028: invalid subscript (not an array or too many subscripts): "NameOfPlayer"
Script.pwn(488) : warning 215: expression has no effect
Script.pwn(488) : error 001: expected token: ";", but found "]"
Script.pwn(488) : error 029: invalid expression, assumed zero
Script.pwn(488) : fatal error 107: too many error messages on one line
Whole code:
pawn Код:
CMD:newbie(playerid, params[])
{
    if(Player[playerid][NMute] == 1) return SendErrorMessage(playerid, "You are unable to use /(n)ewbie, reason: muted");
    new text[255], string[255];
    if(sscanf(params, "s[255]", text)) return SendErrorMessage(playerid, "/(n)ewbie [text]");
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(Player[p][NToggled] != 1 && Player[p][NMute] != 1)
        {
            format(string, sizeof(string), "%s", NameOfPlayer[playerid]);
            SendClientMessage(p, Colour_Newbie_Chat, string);
        }
    }
    return 1;
}
Line of error:
pawn Код:
format(string, sizeof(string), "%s", NameOfPlayer[playerid]);
Reply
#2

In your code, all you're sending is just the NameOfPlayer, so all it will say is:

Quote:

Steve

And that's it, it won't say the text. I fixed that below.

pawn Код:
CMD:newbie(playerid, params[])
{
    if(Player[playerid][NMute] == 1) return SendErrorMessage(playerid, "You are unable to use /(n)ewbie, reason: muted");
    new text[200], string[250];
    if(sscanf(params, "s[200]", text)) return SendErrorMessage(playeid, "/(n)ewbie [text]");
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(Player[p][NToggled] != 1 && Player[p][NMute] != 1)
            {
                format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer[playerid], text); // make sure that your stock for NameOfPlayer has square brackets,
                SendClientMessage(i, Colour_Newbie_Chat, string);
            }
        }
        return 1;
    }
    return 1;
}
Can you show us the stock for NameOfPlayer? It should have square brackets "[playerid]" like it does in the format.
Reply
#3

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
In your code, all you're sending is just the NameOfPlayer, so all it will say is:



And that's it, it won't say the text. I fixed that below.

pawn Код:
CMD:newbie(playerid, params[])
{
    if(Player[playerid][NMute] == 1) return SendErrorMessage(playerid, "You are unable to use /(n)ewbie, reason: muted");
    new text[200], string[250];
    if(sscanf(params, "s[200]", text)) return SendErrorMessage(playeid, "/(n)ewbie [text]");
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(Player[p][NToggled] != 1 && Player[p][NMute] != 1)
            {
                format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer[playerid], text); // make sure that your stock for NameOfPlayer has square brackets,
                SendClientMessage(i, Colour_Newbie_Chat, string);
            }
        }
        return 1;
    }
    return 1;
}
Can you show us the stock for NameOfPlayer? It should have square brackets "[playerid]" like it does in the format.
Oh I know about that it was just for testing at the time here's my stock
pawn Код:
stock NameOfPlayer(id)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(id, pName, sizeof(pName));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(pName[i] == '_') pName[i] = ' ';
    }
    return pName;
}
Reply
#4

Now thanks, I've seen your problem

pawn Код:
format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer[playerid], text);
to
pawn Код:
format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer(playerid), text);
GG Timer
Код:
This forum requires that you wait 240 seconds between posts. Please try again in 136 seconds.
Reply
#5

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Now thanks, I've seen your problem

pawn Код:
format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer[playerid], text);
to
pawn Код:
format(string, sizeof(string), "Newbie chat: %s: %s", NameOfPlayer(playerid), text);
GG Timer
Код:
This forum requires that you wait 240 seconds between posts. Please try again in 136 seconds.
Thank you, didn't notice that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)