Raised This Month: $51 Target: $400
 12% 

Problem with Arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mrshakurr
Junior Member
Join Date: Dec 2011
Old 07-22-2014 , 01:36   Problem with Arrays
Reply With Quote #1

I am trying to make a skin menu so players can buy skins from points they've gained from killing others and I put everything in an array but I get an error.

This is the code.
Code:
enum _:SkinInfo
{
	SkinName[32],
	SkinVModel[64],
	SkinWModel[64],
	SkinPrice,
	SkinOwned[32]
}

new Array:g_iSkins;

public Cmd_SkinShop(id)
{
	new g_iSkinsInfo[ SkinInfo ];
	new menu = menu_create("Skin Shop", "skinshop_handler");
	for(new i = 0; i < ArraySize(g_iSkins); i++)
	{
		ArrayGetArray(g_iSkins, i, g_iSkinsInfo);
		new info[5];
		num_to_str(i, info, 4);
		new item[32];
		if( g_iSkinsInfo[ SkinOwned[id] ] == 0 )
		{
			formatex(item, 31, "%s \r[Price: %i]", g_iSkinsInfo[ SkinName ], g_iSkinsInfo[ SkinPrice ]);
			menu_additem(menu, item, info);
		}
	}
	menu_display(id, menu, 0);
}
In plugin_init, I have this.
Code:
g_iSkins = ArrayCreate(SkinInfo);
And here's the error I'm getting.

Error: Invalid subscript (not an array or too many subscripts): "SkinOwned" on line 145

I don't know what the problem is and any help would be appreciated.
mrshakurr is offline
Eagle07
Veteran Member
Join Date: May 2014
Location: Morocco :D
Old 07-22-2014 , 01:51   Re: Problem with Arrays
Reply With Quote #2

PHP Code:
 if( g_iSkinsInfoSkinOwned[id] ] == 

PHP Code:
 if( g_iSkinsInfoSkinOwned ] == 
__________________
Eagle07 is offline
mrshakurr
Junior Member
Join Date: Dec 2011
Old 07-22-2014 , 02:03   Re: Problem with Arrays
Reply With Quote #3

The array SkinOwned is supposed to store 0 if not owned and 1 if owned for people in the server. I don't get how that will work.
mrshakurr is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-22-2014 , 02:26   Re: Problem with Arrays
Reply With Quote #4

g_ states that it is global yet you create it using new.
__________________
Black Rose is offline
mrshakurr
Junior Member
Join Date: Dec 2011
Old 07-22-2014 , 02:53   Re: Problem with Arrays
Reply With Quote #5

Does name of a variable really matter?
mrshakurr is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-22-2014 , 03:25   Re: Problem with Arrays
Reply With Quote #6

It matters for those of us who are trying to help you because it becomes confusing.

And to get the correct value your actually looking for if( g_iSkinsInfo[ SkinOwned ][ id ] == 0 )
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
mrshakurr
Junior Member
Join Date: Dec 2011
Old 07-22-2014 , 03:27   Re: Problem with Arrays
Reply With Quote #7

Thanks it worked.
mrshakurr is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode