AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Store 3 values (https://forums.alliedmods.net/showthread.php?t=311410)

Spirit_12 10-16-2018 18:37

Store 3 values
 
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"
}; 


shanapu 10-16-2018 18:44

Re: Store 3 values
 
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");



Spirit_12 10-16-2018 19:28

Re: Store 3 values
 
Can you show me an example with multiple text values?

sdz 10-16-2018 20:38

Re: Store 3 values
 
enum
stringmap
keyvalues
standard arrays

shanapu 10-16-2018 20:41

Re: Store 3 values
 
Quote:

Originally Posted by Spirit_12 (Post 2619992)
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");



Spirit_12 10-16-2018 20:54

Re: Store 3 values
 
Quote:

Originally Posted by shanapu (Post 2620003)
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 ?

shanapu 10-16-2018 22:05

Re: Store 3 values
 
Quote:

Originally Posted by Spirit_12 (Post 2620004)
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.

asherkin 10-17-2018 17:01

Re: Store 3 values
 
Enumstructs are discouraged and are not available in modern syntax.

Spirit_12 10-17-2018 18:28

Re: Store 3 values
 
Quote:

Originally Posted by asherkin (Post 2620096)
Enumstructs are discouraged and are not available in modern syntax.

Another alternative?

Neuro Toxin 10-17-2018 18:55

Re: Store 3 values
 
You could use Dynamic as per my Signature.


All times are GMT -4. The time now is 04:42.

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