MAX_STRING Error ?
#1

Hello, I'm getting an error code when you use max_string stock. What is the problem ?

Sorry, For My Bad English.

Please help.

Код:
CMD:test(playerid,params[])
{
kickle(playerid,"ı ğ ь ş ц з");
return 1;
}

stock code(nickname[]) {
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace("ğ","g",tmp);
tmp=strreplace("Ğ","G",tmp);
tmp=strreplace("ş","s",tmp);
tmp=strreplace("Ş","S",tmp);
tmp=strreplace("ı","i",tmp);
tmp=strreplace("I","I",tmp);
tmp=strreplace("İ","I",tmp);
tmp=strreplace("ц","o",tmp);
tmp=strreplace("Ц","O",tmp);
tmp=strreplace("з","c",tmp);
tmp=strreplace("З","C",tmp);
tmp=strreplace("ь","u",tmp);
tmp=strreplace("Ь","U",tmp);
return tmp;
}

stock kickle(playerid, string[])
{
new Years, Months, Days,estring[250];
getdate(Years, Months, Days);
format(estring,sizeof(estring),"{993366}Kickleyen Admin:\t\t{FFFFFF}Anti Hile\n{993366}Sebep:\t\t\t\t{FFFFFF}%s\n{993366}Tarih:\t\t\t\t{FFFFFF}%02d/%02d/%d", string, Days, Months, Years);
ShowPlayerDialog(playerid,123,DIALOG_STYLE_MSGBOX,"{47C9F5}« xPro Gaming » {ffffff}Anti Hile - Kick",estring,"Tamam","");
format(textmesaj,250,"~g~~h~~h~[Anti Hile] ~r~~h~~h~%s(%d) ~w~~h~adli oyuncu sunucudan atildi. Sebep: ~y~~h~%s",getName(playerid),playerid,code(string));
Textdrawyazi(-1, textmesaj);
printf("\n%s(%d) >> kicklendi. Sebep: %s\n",getName(playerid),playerid,code(string));
Kick(playerid);
return 1;
}
Код:
D:\Server\Server\gamemodes\xPro.pwn(30605) : error 017: undefined symbol "MAX_STRING"
D:\Server\Server\gamemodes\xPro.pwn(30605) : error 009: invalid array size (negative, zero or out of bounds)
D:\Server\Server\gamemodes\xPro.pwn(30605) : error 036: empty statement
D:\Server\Server\gamemodes\xPro.pwn(30605) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.

FIX:

Код:
#define MAX_STRING              256

stock strreplace(trg[],newstr[],src[]) {
    new f=0;
    new s1[MAX_STRING];
    new tmp[MAX_STRING];
    format(s1,sizeof(s1),"%s",src);
    f = strfind(s1,trg);
    tmp[0]=0;
    while (f>=0) {
        strcat(tmp,ret_memcpy(s1, 0, f));
        strcat(tmp,newstr);
        format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
        f = strfind(s1,trg);
    }
    strcat(tmp,s1);
    return tmp;
}
ret_memcpy(source[],index=0,numbytes) {
	new tmp[MAX_STRING];
	new i=0;
	tmp[0]=0;
	if (index>=strlen(source)) return tmp;
	if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
	if (numbytes<=0) return tmp;
	for (i=index;i<numbytes+index;i++) {
		tmp[i-index]=source[i];
		if (source[i]==0) return tmp;
	}
	tmp[numbytes]=0;
	return tmp;
}
stock set(dest[],source[]) {
	new count = strlen(source);
	new i=0;
	for (i=0;i<count;i++) {
		dest[i]=source[i];
	}
	dest[count]=0;
}
Reply
#2

have you defined MAX_STRING at start of your code?
PHP код:
 #define MAX_STRING 255 
Reply
#3

Quote:
Originally Posted by GTLS
Посмотреть сообщение
have you defined MAX_STRING at start of your code?
PHP код:
 #define MAX_STRING 255 
Код:
D:\Server\Server\gamemodes\xPro.pwn(30607) : error 017: undefined symbol "set"
D:\Server\Server\gamemodes\xPro.pwn(30608) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30609) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30610) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30611) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30612) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30613) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30614) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30615) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30616) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30617) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30618) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30619) : error 033: array must be indexed (variable "tmp")
D:\Server\Server\gamemodes\xPro.pwn(30620) : error 033: array must be indexed (variable "tmp")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


14 Errors.
Reply
#4

Try using other variable than tmp.. and what do you want to do with set(tmp, nickname) i did not get..
Reply
#5

MAX_STRING is such a dumb thing. It's not as if string sizes have a hard upper limit. Unlike players, vehicles, objects and whatnot. A string should only be as large as it needs to be and as such its size should be determined on a case by case basis. Using MAX_STRING for everything is naive and stupid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)