Raised This Month: $ Target: $400
 0% 

Trouble using sizeof with a string inside an enum


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 09-26-2014 , 12:06   Trouble using sizeof with a string inside an enum
Reply With Quote #1

As the title says. This is the example:
PHP Code:
#include <sourcemod>

enum SomeEnum
{
    
String:sSomeString[32]
};

new 
g_eTesting[MAXPLAYERS 1][SomeEnum];

public 
OnClientConnected(iClient)
{
    
FormatEx(g_eTesting[iClient][sSomeString], sizeof(g_eTesting[iClient][sSomeString][]), "Test String");

I originally tried doing this a couple of weeks ago, and I couldn't figure out a way to do it. I just resorted to manually filling in the string sizes. I am just curious if this is possible and what I am doing wrong. Any input is appreciated.
Marcus_Brown001 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-26-2014 , 12:24   Re: Trouble using sizeof with a string inside an enum
Reply With Quote #2

I'm a little bit confused because you use a string as an array index, but this should be what you want:
PHP Code:
FormatEx(g_eTesting[iClient][sSomeString], sizeof(g_eTesting[][]), "Test String"); 
__________________

Last edited by Impact123; 09-26-2014 at 12:27.
Impact123 is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 09-26-2014 , 12:28   Re: Trouble using sizeof with a string inside an enum
Reply With Quote #3

I usually just define a constant in these cases and use that.
__________________

Last edited by pheadxdll; 09-26-2014 at 12:31.
pheadxdll is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-26-2014 , 12:43   Re: Trouble using sizeof with a string inside an enum
Reply With Quote #4

Quote:
Originally Posted by Impact123 View Post
I'm a little bit confused because you use a string as an array index, but this should be what you want:
PHP Code:
FormatEx(g_eTesting[iClient][sSomeString], sizeof(g_eTesting[][]), "Test String"); 
I believe that would get the size of the total enum.
It would just be easier (less messy) to just use defines.

I would try any:
sizeof(g_eTesting[iClient][sSomeString][]);
sizeof(g_eTesting[][sSomeString][]);

Last edited by Mitchell; 09-26-2014 at 12:44.
Mitchell is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-26-2014 , 14:58   Re: Trouble using sizeof with a string inside an enum
Reply With Quote #5

This is the problem with enums in sourcemod.
Usually I just use defines for everything to prevent this.
Besides, those hacky enum/struct things are nit exactly human readably.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram 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 20:27.


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