Got a little prob. with error 008.
#1

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
Reply
#2

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.
Reply
#3

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[])
Reply
#4

Sorry, I was thinking of another system.

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

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;
}
Reply
#6

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

It worked! Thanks very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)