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

Strings in Enums (Array out of bounds)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sdz
Senior Member
Join Date: Feb 2012
Old 02-05-2015 , 01:48   Strings in Enums (Array out of bounds)
Reply With Quote #1

Having some trouble on something that makes no sense...

Yes I've tried hardcoding it to [32], Tried using a macro, tried using [32+1]
PHP Code:
#define MAXGANGS 200
//////////////////////////////
///        Gang Mod       ///
/////////////////////////////
enum GangData
{
    
String:Gang_Name[32],
    
String:Gang_Tag[32],
    
String:Gang_Leader[32],
    
String:Gang_Model[32],
    
Gang_357 0,
    
Gang_Shotgun 0,
    
Gang_Nade 0,
    
Gang_Crossbow 0,
    
Gang_AR2 0,
    
Gang_RPG 0,
    
Gang_SMG 0,
    
Gang_Pistol 0,
    
Gang_Suit 0,
    
Gang_MemberLVL 1
}

enum GangDataPlayer
{
    
String:Gang_Name[32],
    
String:Gang_Tag[32],
    
Gang_Rank 0
}

new 
g_GangIndex;
new 
g_Gang[MAXGANGS][GangData];
new 
g_Gang_Player[MAXPLAYERS 1][GangDataPlayer]; 
Throwing me Array out of bounds and array sizes do not match on simple things such as..
PHP Code:
SQL_FetchString(hHndl4g_Gang[g_GangIndex][Gang_Leader], 32);
SQL_FetchString(hHndl5g_Gang[g_GangIndex][Gang_Name], 32);
SQL_FetchString(hHndl6g_Gang[g_GangIndex][Gang_Tag], 32);
SQL_FetchString(hHndl7g_Gang[g_GangIndex][Gang_Model], 32); 
Client Example:
PHP Code:
decl String:sInfo[32], String:sInfo2[32];
ReadPackString(g_hInvitePacksInfosizeof(sInfo));
ReadPackString(g_hInvitePacksInfo2sizeof(sInfo2));
strcopy(g_Gang_Player[Client][Gang_Name], 32sInfo);
strcopy(g_Gang_Player[Client][Gang_Tag], 32sInfo2); 
wtf.
Save me please

Last edited by sdz; 02-05-2015 at 01:56.
sdz is offline
sdz
Senior Member
Join Date: Feb 2012
Old 02-05-2015 , 02:05   Re: Strings in Enums (Array out of bounds)
Reply With Quote #2

Double:
I change stuff around like so.. and it compiles fine. I was also just informed that you can't assign defaults to enum stuffs.
PHP Code:
enum GangData
{
    
Gang_357 0,
    
Gang_Shotgun 0,
    
Gang_Nade 0,
    
Gang_Crossbow 0,
    
Gang_AR2 0,
    
Gang_RPG 0,
    
Gang_SMG 0,
    
Gang_Pistol 0,
    
Gang_Suit 0,
    
Gang_MemberLVL 1,
    
String:Gang_Name[32],
    
String:Gang_Tag[32],
    
String:Gang_Leader[32],
    
String:Gang_Model[32]
}

enum GangDataPlayer
{
    
Gang_Rank 0,
    
String:Player_Gang[32],
    
String:Player_Tag[32]

sdz is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 02-05-2015 , 02:10   Re: Strings in Enums (Array out of bounds)
Reply With Quote #3

<3 for sharing the solution and not blanking out posts like other people unfortunately do these days.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-05-2015 , 07:36   Re: Strings in Enums (Array out of bounds)
Reply With Quote #4

Details on the whole default values situation: https://forums.alliedmods.net/showth...37#post1685437
__________________
asherkin is offline
ici
Member
Join Date: Jan 2014
Old 02-05-2015 , 13:20   Re: Strings in Enums (Array out of bounds)
Reply With Quote #5

Talking of Enums and Strings, instead of me making a new thread, can somebody tell me how to use multi-dimensional arrays (strings) in Enums please?

PHP Code:
enum MyEnum
{
    
String:Buffer[32][256],
    ...

I'm getting an error when compiling (error 001: expected token: "}", but found "[")

I found some info here https://forums.alliedmods.net/showth...=140103&page=7 (Post #66) but I'm having troubles transforming that Buffer string on my own. If somebody could break it down for me, I'd be thankful.

Last edited by ici; 02-05-2015 at 13:20.
ici is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-05-2015 , 13:28   Re: Strings in Enums (Array out of bounds)
Reply With Quote #6

As that post says, you can't, need to use multiple separate strings.
__________________
asherkin is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 02-05-2015 , 13:37   Re: Strings in Enums (Array out of bounds)
Reply With Quote #7

what you can do in exchange is

PHP Code:
enum myStringArray
{
    
String:m_one[32],
    
String:m_two[32]
};

enum myStruct
{
    
m_strings[myStringArray],
    ...
};

struct[m_strings][m_one

Last edited by Mathias.; 02-05-2015 at 13:37.
Mathias. 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 21:55.


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