must be assigned to an array
#1

I've made a dcmd command but I get "must be assigned to an array" error on this line:

pawn Код:
PlayerInfo[playerid][pSecKey] = params;
Thanks in advance.
Reply
#2

PlayerInfo[playerid][pSecKey] = params[0];
Reply
#3

pawn Код:
PlayerInfo[playerid][pSecKey] = params[0];
EDIT: User above was faster.
Reply
#4

Quote:
Originally Posted by Pharrel
Посмотреть сообщение
PlayerInfo[playerid][pSecKey] = params[0];
Well no.. the params I typed in were "0000" and it set pSecKey to "48" ?

Whole command:
pawn Код:
dcmd_changeakey(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new string[126];
        if(!strlen(params)) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /changeakey [4 digits]");
        if(!IsNumeric(params)) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be digits only !");
        new length = strlen(params);
        if(length !=4) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
        PlayerInfo[playerid][pSecKey] = params[0];
        format(string, sizeof(string), "* Security key changed to: %d !", PlayerInfo[playerid][pSecKey]);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
    return 1;
}
Reply
#5

Why don't you just use sscanf, a lot easier and faster...
Reply
#6

pawn Код:
dcmd_changeakey(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new string[55];
        if(!IsNumeric(params[0])) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be digits only !");
        if(9999 > params[0] < 1000) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
        PlayerInfo[playerid][pSecKey] = params[0];
        format(string, sizeof(string), "* Security key changed to: %d !", PlayerInfo[playerid][pSecKey]);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
    return 1;
}
in only 1 parameter is faster dont use sscanf...
Reply
#7

Quote:
Originally Posted by [MWR]Blood
Посмотреть сообщение
Why don't you just use sscanf, a lot easier and faster...
Tried and got:
Код:
error 035: argument type mismatch (argument 1)
With:
pawn Код:
dcmd_changeakey(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new key, string[126];
        if(sscanf(params, "i", key)) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /changeakey [4 digits]");
        if(!IsNumeric(key)) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be digits only !");
        new length = strlen(key);
        if(length !=4) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
        PlayerInfo[playerid][pSecKey] = key;
        format(string, sizeof(string), "* Security key changed to: %d !", key);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
    return 1;
}
Edit:
@Pharrel

Yours didn't work, kept saying "* Your security key must be 4 digits long only !"
Reply
#8

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
Tried and got:
Код:
error 035: argument type mismatch (argument 1)
With:
pawn Код:
dcmd_changeakey(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new key, string[126];
        if(sscanf(params, "i", key)) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /changeakey [4 digits]");
        if(!IsNumeric(key)) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be digits only !");
        new length = strlen(key);
        if(length !=4) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
        PlayerInfo[playerid][pSecKey] = key;
        format(string, sizeof(string), "* Security key changed to: %d !", key);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
    return 1;
}
Which line gave you this error ?
Reply
#9

pawn Код:
dcmd_changeakey(playerid, params[])
{
    new key, string[126];
    if(!(PlayerInfo[playerid][pAdmin] >= 1)) return 0;
    if(sscanf(params, "i", key)) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /changeakey [4 digits]");
    if(key > 9999 || key < 1000) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
    PlayerInfo[playerid][pSecKey] = key;
    format(string, sizeof(string), "* Security key changed to: %d !", key);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}
Reply
#10

Well, first of all, you don't need this
pawn Код:
if(!IsNumeric(key)) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be digits only !");
Second, you could just do
pawn Код:
if(strlen(key) != 4) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Your security key must be 4 digits long only !");
        PlayerInfo[playerid][pSecKey] = key;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)