SA-MP Forums Archive
Got a little prob. with error 008. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Got a little prob. with error 008. (/showthread.php?tid=205558)



Got a little prob. with error 008. - sobolanux - 01.01.2011

Hi there. I`ve got a little problem with the error 008. I made a function, and it has a little bug which I can`t currently fix. If you could help...

Function
Код:
public SendMOTD(playerid)
{
	new  motd_s[256], x[10];
	x = "motd";
 	format(motd_s, sizeof(motd_s), "/Settings/%s.ini", x);
  	new motd[128] = dini_Get(motd_s, "motd"); // error line
   	SendClientMessage(playerid, COLOR_RED, motd);
}
Error
Код:
error 008: must be a constant expression; assumed zero



Re: Got a little prob. with error 008. - Grim_ - 01.01.2011

You do not need to use motd, the function automatically stores the result into the array 'motd_s'
pawn Код:
public SendMOTD(playerid)
{
    new  motd_s[256], x[10];
    x = "motd";
    format(motd_s, sizeof(motd_s), "/Settings/%s.ini", x);
    dini_Get(motd_s, "motd"); // error line
    SendClientMessage(playerid, COLOR_RED, motd_s);
}
Anyway, I do not suggest using dini. Very outdated and inefficient.


Re: Got a little prob. with error 008. - sobolanux - 01.01.2011

That really isn`t the problem. As I look through the function`s syntax , the "motd_s", it`s the filename:

Код:
dini_Get(filename[],key[])



Re: Got a little prob. with error 008. - Grim_ - 01.01.2011

Sorry, I was thinking of another system.

Can you please copy and paste the dini_Get function from the library?


Re: Got a little prob. with error 008. - sobolanux - 01.01.2011

Here:

Код:
stock dini_Get(filename[],key[]) {
	new tmpres[DINI_MAX_STRING];
	
	new key_length = strlen(key);
	if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;
	
	new File:fohnd;
	fohnd=fopen(filename,io_read);
	if (!fohnd) return tmpres;
	
	while (fread(fohnd,tmpres)) {
		if (
			tmpres[key_length]=='='
			&& !strcmp(tmpres, key, true, key_length)	
		) {
			/* We've got what we need */
			DINI_StripNewLine(tmpres);
			strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
			fclose(fohnd);
			return tmpres;
		}
	}
	fclose(fohnd);
	return tmpres;
}



Re: Got a little prob. with error 008. - Grim_ - 01.01.2011

pawn Код:
public SendMOTD(playerid)
{
    new str[ 128 ];
    format( str, sizeof( str ), "%s", dini_Get( "/Settings/motd.ini", "motd" ) );
    SendClientMessage( playerid, COLOR_RED, str );
}
That should work. Let me know.


Re: Got a little prob. with error 008. - sobolanux - 01.01.2011

It worked! Thanks very much!