Enumerator Help
#1

Код:
enum pInfo
{
  pStrKey[128],
  pIntLevel,
  pIntSex
};
new PlayerInfo[MAX_PLAYERS][pInfo];
With an enumerator setup like that, how would I retrieve both the value of "pIntSex" and the actual string defined as "pIntSex", using a number.

Код:
PlayerInfo[playerid][1]
Will not work, it reports tag mismatch warnings, and rightfully so. Are there any functions or workarounds to get this done?

Thanks for your time.
Reply
#2

None that I'm actually aware of. In one of my recent inventory scripts, I had to seperate the item names from the rest of the enumerated variables, due to similar issues.

Not from script, just an example.
pawn Код:
enum info
{
  pAdmin,
  pCash,
  pBackPack,
}
new PlayerInfo[MAX_PLAYERS][info];
new pItemNames[MAX_PLAYERS][MAX_ITEMS][MAX_ITEM_NAME];
new pItemAmounts[MAX_PLAYERS][MAX_ITEMS]
Reply
#3

I tried another way of doing this:

Код:
new pInfoIndex[][] = {
  "pStrKey",
  "pIntLevel"
  "pIntSex"
};
I then tried calling the correct array like this:

Код:
PlayerInfo[playerid][pInfoIndex[i]]
Problem was it thinks "pInfoIndex" is an array defined in the enumerator instead of a separated array that will just call the name of the true array defined in the enumerator. Anyone know a way around that?
Reply
#4

pawn Код:
enum //no name
{
  pStrKey[128],
  pIntLevel,
  pIntSex
}
new PlayerInfo[MAX_PLAYERS][130]; //size of the total array, 128 chars + 2 integers = 130

//usage
PlayerInfo[0] = "some string here";
PlayerInfo[0][ 128 ] = 33;
PlayerInfo[0][ 129 ] = 4444444;
printf("%s,%d,%d", PlayerInfo[0], PlayerInfo[0][128], PlayerInfo[0][129]);
Should print:

Quote:

some string here,33,4444444

Don't quote my on this though
Reply
#5

Thanks for the reply Donny.

Unfortunately your code really doesn't do the tricks needed.

Using just numbers to define the arrays works to an extent but it also removes the ability to store strings within those arrays as far as I know. It also becomes confusing for calling values later on in programming.

I would need to call "3" instead of "pIntSex" which is easy enough with the small amount of variables currently there but once there is over 20, I'm not going to be able to easily tell what variable I'm calling at all.
Reply
#6

Quote:
Originally Posted by Pload
Thanks for the reply Donny.

Unfortunately your code really doesn't do the tricks needed.

Using just numbers to define the arrays works to an extent but it also removes the ability to store strings within those arrays as far as I know. It also becomes confusing for calling values later on in programming.

I would need to call "3" instead of "pIntSex" which is easy enough with the small amount of variables currently there but once there is over 20, I'm not going to be able to easily tell what variable I'm calling at all.
Yeah I though the exact same thing while replying (tracking large amounts woud become confusing) but thought I'd throw it out anyway.

Bloody chars ay, they spoil all the fun.

You could always use two enums to track them (or macros):

pawn Код:
enum
{
  pStrKey[128]
  pIntLevel,
  pIntSex
}

enum
{  
  pIntLevel_IDX = 128, //pStrKey size (0 - 127)
  pIntSex_IDX //129
}
Usage:
pawn Код:
PlayerInfo[0][pIntSex_IDX] = .... //pIntSex_ID is 129, 129 is pIntSex in the array slots, based on my above example
Again it's a kind of solution but would require more work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)