Two dimensional array help
#1

Код:
new PhoneName[][] =
{
	{"Nokia 203", 500},
	{"Nokia Lumia 610", 2000},
	{"Sony Xperia Ion", 1700},
	{"Samsung Galaxy S4", 3500},
	{"Samsung Galaxy Nexus", 3400},
	{"HTC Desire X", 2900},
	{"Apply iPhone 5S", 5000},
	{"Huawei Y200", 1500},
	{"Apple iPhone 6", 6000},
	{"Samsung Galaxy S5", 5500},
	{"Nokia Lumia 900", 2800},
	{"Nokia N9", 2100}
};
Код:
CMD:buy(playerid, params[])
{
	new string[128];
	if(IsPlayerInRangeOfPoint(playerid, 1.0, -2286.1260,-155.3922,3346.8701))
	{
		new price[ sizeof(PhoneName) ];
		for(new p; p < sizeof(PhoneName); p++)
		{
			price[p] = PhoneName[p][1];
		}
		format(string, sizeof(string), "%s\n%s ($%d)", string, PhoneName[p][0], price[p]);
		return ShowPlayerDialog(playerid, DIALOG_TMOBILE, DIALOG_STYLE_LIST, "T-Mobile list", string, "Select", "Cancel");
	}
return 1;
}
What its print: http://prntscr.com/612ub4

I have never used this array style, i tried myelf but the phone prices aren't correct, please help me out +REP
Reply
#2

Код:
format(string, sizeof(string), "%s\n%s ($%d)", string, PhoneName[p][0], price[p]);
I'd hazard a guess that that line, has something to do with it. In particular you're formatting string, yet using string in the format.

Also notice that it's not doing the full list either, it's only doing 5-6, and the last one doesn't even have its price.
Reply
#3

You can't mix strings and integers in the same array.
You should get errors if you compile.

The first index of your array points to the line, the second index points to the phone-names, but it cannot store the prices.

You need to use an enum to pull this off, or use 2 separate arrays, one for the phonenames and another for the prices.
Reply
#4

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
You need to use an enum to pull this off, or use 2 separate arrays, one for the phonenames and another for the prices.
While you're around, what's better in this scenario, enum, or 2 arrays...


And what about in further cases, where more data is held, at what stage does there end up being too many for an enum/2 arrays?




six hundred and sixty six! WOOT!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)