AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with Arrays (https://forums.alliedmods.net/showthread.php?t=244676)

mrshakurr 07-22-2014 01:36

Problem with Arrays
 
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.

Eagle07 07-22-2014 01:51

Re: Problem with Arrays
 
PHP Code:

 if( g_iSkinsInfoSkinOwned[id] ] == 

:arrow:
PHP Code:

 if( g_iSkinsInfoSkinOwned ] == 


mrshakurr 07-22-2014 02:03

Re: Problem with Arrays
 
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.

Black Rose 07-22-2014 02:26

Re: Problem with Arrays
 
g_ states that it is global yet you create it using new.

mrshakurr 07-22-2014 02:53

Re: Problem with Arrays
 
Does name of a variable really matter?

hornet 07-22-2014 03:25

Re: Problem with Arrays
 
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 )

mrshakurr 07-22-2014 03:27

Re: Problem with Arrays
 
Thanks it worked.


All times are GMT -4. The time now is 13:12.

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