SA-MP Forums Archive
array must be indexed (variable "String") - 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: array must be indexed (variable "String") (/showthread.php?tid=387393)



sscanf warning: Strings without a length are deprecated, please add a destination size. - Opah - 24.10.2012

pawn Код:
COMMAND:changename(playerid,params[])
{
    new String[24];if(sscanf(params,"s",String)) return SendClientMessage(playerid,COLOR_RED,""WHITE"Usage:"GREEN"/changename "WHITE"[playerid]");
    if(String > 24 ) return SendClientMessage(playerid,COLOR_RED,"ERROR : the name must be smaller than 24 characters");
    new file[50];format(file,50,"Users/%s.ini",String);//    ==> error line
    if(fexist(file)) return SendClientMessage(playerid,COLOR_RED,"ERROR : the name you have chosen is used by somebody else please choose another one");
    new str[256];
    format(str,256,"%s,%s",pInfo[playerid][Aka],String);
    pInfo[playerid][Aka] = str;
    SetPlayerName(playerid,String);
    return 1;
}
Код:
array must be indexed (variable "String")



Re: array must be indexed (variable "String") - iggy1 - 24.10.2012

Код:
if(String > 24 )
To
Код:
if(strlen(String) > 24 )



Re: array must be indexed (variable "String") - gtakillerIV - 24.10.2012

Use

PHP код:
if(strlen(String) > 24) return SendClientMessage(playerid,COLOR_RED,"ERROR :...."); 
EDIT:
Iggy was faster


Re: array must be indexed (variable "String") - Jarnu - 24.10.2012

Well iggy his error line is :

pawn Код:
new file[50];format(file,50,"Users/%s.ini",String);//    ==> error line
And also shouldn't it be

pawn Код:
if(strlen(String) > 24)
like this ^?


Re: array must be indexed (variable "String") - Opah - 24.10.2012

worked thanx all


Re: array must be indexed (variable "String") - Opah - 24.10.2012

okay now it prints me this
Код:
[19:28:27] sscanf warning: Strings without a length are deprecated, please add a destination size.
[19:28:27] [nick] [BFV]Opah[COD5] nick changed to name1
[19:28:30] sscanf warning: Strings without a length are deprecated, please add a destination size.
[19:28:30] [nick] name1 nick changed to name2
[19:28:32] [part] name2 has left the server (0:1)



Re: array must be indexed (variable "String") - gtakillerIV - 24.10.2012

PHP код:
if(sscanf(params,"s",String)) return SendClientMessage(playerid,COLOR_RED,""WHITE 
Should be:

PHP код:
if(sscanf(params,"s[24]",String)) return SendClientMessage(playerid,COLOR_RED,""WHITE 
Whole command will be:

PHP код:
COMMAND:changename(playerid,params[])
{
    new 
String[24];
    if(
sscanf(params,"s[24]",String)) return SendClientMessage(playerid,COLOR_RED,""WHITE"Usage:"GREEN"/changename "WHITE"[playerid]");
    if(
strlen(String) > 24 ) return SendClientMessage(playerid,COLOR_RED,"ERROR : the name must be smaller than 24 characters");
    new 
file[50];
    
format(file,50,"Users/%s.ini",String);
    if(
fexist(file)) return SendClientMessage(playerid,COLOR_RED,"ERROR : the name you have chosen is used by somebody else please choose another one");
    new 
str[256];
    
format(str,256,"%s,%s",pInfo[playerid][Aka],String);
    
pInfo[playerid][Aka] = str;
    
SetPlayerName(playerid,String);
    return 
1;




Re: array must be indexed (variable "String") - Opah - 24.10.2012

thanx it worked


Re: array must be indexed (variable "String") - gtakillerIV - 24.10.2012

Your welcome.