Raised This Month: $66 Target: $400
 16% 

Store 3 values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-16-2018 , 19:37   Store 3 values
Reply With Quote #1

I need to store 3 values in an array. Not sure what would be the best approach for this.

For example:
  • Client Index
  • bool value
  • Some text

If it was just two sets of data, I could have done something like this.

PHP Code:
char TeamNames[][] = {
"NONE",
"SPEC",
"SURV",
"INFC"
}; 
__________________
Spirit_12 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-16-2018 , 19:44   Re: Store 3 values
Reply With Quote #2

maybe use an enum
PHP Code:
enum Values
{
    
bool:bValue,
    
String:sValue[32]
}

any g_aValues[MAXPLAYERS 1][Values];

void myfunction(int client)
{
    
g_aValues[client][bValue] = true;

    
strcopy(g_aValues[client][sValue], 32"Value");

__________________
free software
coding
shanapu is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-16-2018 , 20:28   Re: Store 3 values
Reply With Quote #3

Can you show me an example with multiple text values?
__________________
Spirit_12 is offline
sidezz
Senior Member
Join Date: Feb 2012
Location: United States
Old 10-16-2018 , 21:38   Re: Store 3 values
Reply With Quote #4

enum
stringmap
keyvalues
standard arrays
__________________

Last edited by sidezz; 10-16-2018 at 21:38.
sidezz is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-16-2018 , 21:41   Re: Store 3 values
Reply With Quote #5

Quote:
Originally Posted by Spirit_12 View Post
Can you show me an example with multiple text values?
Not sure if that's what you're asking, nor if that's a good way to go.

PHP Code:
enum Values
{
    
bool:bValue,
    
String:sValue1[32]
    
String:sValue2[32]
    
String:sValue3[32]
}

any g_aValues[MAXPLAYERS 1][Values];

void myfunction(int client)
{
    
g_aValues[client][bValue] = true;

    
strcopy(g_aValues[client][sValue1], 32"Value1");
    
strcopy(g_aValues[client][sValue2], 32"Value2");
    
strcopy(g_aValues[client][sValue3], 32"Value3");

or


PHP Code:
enum Strings
{
    
String:sValue1[32],
    
String:sValue2[32],
    
String:sValue3[32]
}

enum Values
{
    
bool:bValue,
    
aStrings[Strings]
}

any g_aValues[MAXPLAYERS 1][Values];

void myfunction(int client)
{
    
g_aValues[client][bValue] = true;

    
strcopy(g_aValues[client][aStrings][sValue1], 32"Value1");
    
strcopy(g_aValues[client][aStrings][sValue2], 32"Value2");
    
strcopy(g_aValues[client][aStrings][sValue3], 32"Value3");

__________________
free software
coding
shanapu is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-16-2018 , 21:54   Re: Store 3 values
Reply With Quote #6

Quote:
Originally Posted by shanapu View Post
Not sure if that's what you're asking, nor if that's a good way to go.

PHP Code:
enum Values
{
    
bool:bValue,
    
String:sValue1[32]
    
String:sValue2[32]
    
String:sValue3[32]
}

any g_aValues[MAXPLAYERS 1][Values];

void myfunction(int client)
{
    
g_aValues[client][bValue] = true;

    
strcopy(g_aValues[client][sValue1], 32"Value1");
    
strcopy(g_aValues[client][sValue2], 32"Value2");
    
strcopy(g_aValues[client][sValue3], 32"Value3");

or


PHP Code:
enum Strings
{
    
String:sValue1[32],
    
String:sValue2[32],
    
String:sValue3[32]
}

enum Values
{
    
bool:bValue,
    
aStrings[Strings]
}

any g_aValues[MAXPLAYERS 1][Values];

void myfunction(int client)
{
    
g_aValues[client][bValue] = true;

    
strcopy(g_aValues[client][aStrings][sValue1], 32"Value1");
    
strcopy(g_aValues[client][aStrings][sValue2], 32"Value2");
    
strcopy(g_aValues[client][aStrings][sValue3], 32"Value3");

This makes sense, but why would you say its not a good way to go ?
__________________
Spirit_12 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-16-2018 , 23:05   Re: Store 3 values
Reply With Quote #7

Quote:
Originally Posted by Spirit_12 View Post
This makes sense, but why would you say its not a good way to go ?
I said "Not sure if ... that's a good way to go" ..., depending on what you want/need.

I just started working with enums much more intense and very like them, maybe I just haven't encountered the disadvantages yet.

Maybe a StringMap or KeyValues or just some more arrays (like sidezz mentioned above) would fit your needs better. No idea how expensive the individual classes are.
__________________
free software
coding
shanapu is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-17-2018 , 18:01   Re: Store 3 values
Reply With Quote #8

Enumstructs are discouraged and are not available in modern syntax.
__________________
asherkin is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-17-2018 , 19:28   Re: Store 3 values
Reply With Quote #9

Quote:
Originally Posted by asherkin View Post
Enumstructs are discouraged and are not available in modern syntax.
Another alternative?
__________________
Spirit_12 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-17-2018 , 19:55   Re: Store 3 values
Reply With Quote #10

You could use Dynamic as per my Signature.
__________________
Neuro Toxin is online now
Reply


Thread Tools
Display Modes

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 05:05.


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