1D/2D Arrays with stock
#1

Hi,

why this isn't working?
Код:
stock UpdateFileDetails2(Float: times[5], players[5][MAX_PLAYER_NAME+1])
{
	iniFile = INI_Open(fileToWrite);
	INI_SetTag(iniFile, "times");
	new sValue[10];
	for(new i = 0; i < 5; i++)
	{
		valstr(sValue, i);
		INI_WriteFloat(iniFile, sValue, times[i], 4);
	}
	
	INI_SetTag(iniFile, "players");
	new arr[] = {"1st", "2nd", "2rd", "4th", "5th"};
	for(new m = 0; m < 5; m++) INI_WriteString(iniFile, arr[m], players[m]);
	INI_Close(iniFile);
}
USAGE:
UpdateFileDetails2(10.0, 10.0, 10.0, 10.0, 10.0, "N/A", "N/A", "N/A", "N/A", "N/A");
UpdateFileDetails2(ccount[3][playerid], tops[0], tops[1], tops[2], tops[3], name[playerid], usrtops[0], usrtops[1], usrtops[2], usrtops[3]);

Код:
ERRORS:
MyCode.pwn(84) : error 035: argument type mismatch (argument 1)
// UpdateFileDetails2(10.0, 10.0, 10.0, 10.0, 10.0, "N/A", "N/A", "N/A", "N/A", "N/A");
MyCode.pwn(85) : error 047: array sizes do not match, or destination array is too small
// UpdateFileDetails2(ccount[3][playerid], tops[0], tops[1], tops[2], tops[3], pName[playerid], usrtops[0], usrtops[1], usrtops[2], usrtops[3]);
Variables:
Код:
new 
	Float: ccount[4][MAX_PLAYERS],
	Float: tops[5],
	usrtops[5][MAX_PLAYER_NAME + 1]
;
by the way, i want to add option to my function that ables me to choose which keys change.
something like that:
Код:
UpdateFileDetails(key, value, key, value);
by numargs functions (core.inc)
how can i do it?
And of course to choose the type, Float/String

i think i can do it with enumartion, something like KeysUpdateTypes and using switch + loop (for numargs)
Код:
enum KeysUpdateTypes { Float: times[5], players[5][MAX_PLAYER_NAME + 1] };
stock UpdateFileDetails({KeysUpdateTypes}:...)
{
iniFile = INI_Open(fileToWrite);
for(new i = 0, n = numargs(); i < n; i++) switch(getarg(i))
{
case times[0]: INI_WriteFloat(iniFile, "0", getarg(i+1), 4);
// another times cases.
case players[0]: INI_WriteString(iniFile, "1st", getarg(i+1));
}
INI_Close(iniFile);
return 1;
}
It should work?
If there is a better way, I'd be happy to see it.
Reply
#2

If the function expects an array then you must pass an array. For example:
pawn Код:
new array1[5] = {10.0, ...};
new array2[5][MAX_PLAYER_NAME+1] = { "N/A", "N/A", "N/A", "N/A", "N/A" };

UpdateFileDetails2(array1, array2);
Or shorthand:
pawn Код:
UpdateFileDetails2({10.0, 10.0, 10.0, 10.0, 10.0}, {"N/A", "N/A", "N/A", "N/A", "N/A"});
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
If the function expects an array then you must pass an array. For example:
pawn Код:
new array1[5] = {10.0, ...};
new array2[5][MAX_PLAYER_NAME+1] = { "N/A", "N/A", "N/A", "N/A", "N/A" };

UpdateFileDetails2(array1, array2);
Or shorthand:
pawn Код:
UpdateFileDetails2({10.0, 10.0, 10.0, 10.0, 10.0}, {"N/A", "N/A", "N/A", "N/A", "N/A"});
pawn Код:
new Float: times[5] = {0.0, ...};
new players[5][MAX_PLAYER_NAME+1] = { "N/A", "N/A", "N/A", "N/A", "N/A" };

stock UpdateFileDetails2(times, players)
{
    iniFile = INI_Open(fileToWrite);
    INI_SetTag(iniFile, "times");
    new sValue[10], i = 0;
    for(i = 0; i < 5; i++)
    {
        valstr(sValue, i);
        INI_WriteFloat(iniFile, sValue, times[i], 4);
    }
   
    INI_SetTag(iniFile, "players");
    new arr[] = {"1st", "2nd", "2rd", "4th", "5th"};
    for(i = 0; i < 5; i++) INI_WriteString(iniFile, arr[i], players[i]);
    INI_Close(iniFile);
}
?
and how i use the arrays in the function?
Reply
#4

Another comment?
BUMP.
Reply
#5

BUMP.. WTHF
Reply
#6

Not knowing type of variable at compilation time can be pain in the ass, arrays are easier to implement in your case.

pawn Код:
stock UpdateFileDetails2(Float:times[], players[][])
Try this
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)