SA-MP Forums Archive
must be assigned to an array - 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: must be assigned to an array (/showthread.php?tid=287179)



must be assigned to an array - Jack_Leslie - 02.10.2011

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.


Re: must be assigned to an array - Pharrel - 02.10.2011

PlayerInfo[playerid][pSecKey] = params[0];


Re: must be assigned to an array - Jafet_Macario - 02.10.2011

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


Re: must be assigned to an array - Jack_Leslie - 02.10.2011

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;
}



Re: must be assigned to an array - [MWR]Blood - 02.10.2011

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


Re: must be assigned to an array - Pharrel - 02.10.2011

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...


Re: must be assigned to an array - Jack_Leslie - 02.10.2011

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 !"


Re: must be assigned to an array - =WoR=G4M3Ov3r - 02.10.2011

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 ?


Re: must be assigned to an array - Jafet_Macario - 02.10.2011

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;
}



Re: must be assigned to an array - [MWR]Blood - 02.10.2011

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;