Array index (proprocessor) ?
#1

Hello,
i need find index of array in compile time. Like this:

Код:
new ArrayString[][] = {
	/*
	some string lines
	*/
	{"some string"},
	/* something like #define ARRAY_INDEX = */{"my string"},//Index of this is 1 (but i don't now it)
	{"string continue"},
	/*
	some string lines
	*/
};

public OnFilterScriptInit()
{
	printf("index of array ArrayString where text is 'my string' = %d",ARRAY_INDEX);//index is 1
	return 1;
}
Is there anything to do?
Thanks for help.
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Why? If you need static access to it, put it in a separate variable.
I use it for lists that are often changing.
Such as a list of settings.
Or the list of updates on my server. I will add upgrades to the latest updates, but I want to access another line of update
When I add a row to top, all index will +1.
I add very often.

Код:
new ListOfUpdates[][] = {
	/*
	add new update on top
	*/
	"Update 3: Smaller update",
/*
some updates
*/
	"Update 2: Very big and interesting update",
/*
some updates
*/
	"Update 1: Add something"
/*
1000 old updates
*/
};

cmd:updates(playerid,params[])
{
	//show first 10 lines (new updates)
}

cmd:bigupdate(playerid,params[])
{
	//show 10 lines of update 2 (i don't now the index of 'Update 2:...')
}
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
Why not add updates to the end instead?
Because I want the latest updates to be up and the older ones down

Код:
cmd:updates(playerid,params[])
{
	new string[1024];
	for(new i;i<LINES_OF_UPDATES;i++)
	{
		strcat(string,ListOfUpdates[i]);
		strcat(string,"\n");
	}
	ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,"Updates",string,"Close","");
	return 1;
}
It's quick and simple
Reply
#4

Well, I did not give the best example.
But thanks for the example of the cycle, use it in this form (subtract in the space for the condition) I did not think. But it makes sense and it's elegant. I will definitely use it in the future

So if I understand correctly. Can not get index in array?

Another example:

I have a list of settings, and it is maintained in alphabetical order. When I add a line, so abediently.

Код:
new Settings[][] = {
	"Gravity",
	"Max money in pocket",
	/*
	i want add:
	"Max weapon ammo"
	*/
	"Time",
	"Weather",//index is 4. Bud when i add line index is will be 5
};

new SettingValue[sizeof(Settings)];//integer value for setting (for Weather for example id 16 (rain))

prikaz:getsettime(playerid,params[])
{
	new index = ??;
	new string[144];
	format(string,sizeof(string),"%s is set to %d",Settings[index],SettingValue[index]);
	SendClientMessage(playerid,0xFFFFFFFF,string);
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)