Enum tag inside another enum?
#1

Is there any possiblity of using a double-enum tag (I will provide an example below) without getting a tag mismatch error AND without having to put _: to clear it?

It's quite a stupid question as it is asked out of lazyness, but I'm just wondering.

Say you have a code like this:

pawn Код:
enum E_MY_ENUM
{
    E_DATA1,
    E_DATA2
};

enum E_MY_2ND_ENUM
{
    E_MY_ENUM:E2_DATA1,
    E2_DATA2
};

new
    MyVar[ E_MY_2ND_ENUM ]
;
I would then like to use it like this:

pawn Код:
MyVar[ E2_DATA1 ] = E_DATA2;
EDIT: I misspoke. That code above does NOT give me a warning, but if I try to print the data, then I do. I would like to be able to print out the value and use it as an integer, kind of.

Because of lazyness, I would like to not having to do so, but still don't get a tag mismatch warning.

I tried making a macro for it as a last resort (see below), but that crashed my compiler.

pawn Код:
#define MyVar _:MyVar
I also tried another way of doing it, by calling the variable something really... weird, then make a macro called MyVar to "mimic" that variable, but when I then assigned that variable I got another warning saying that the tag was being hidden:

pawn Код:
#define MyVar _:TESTVARIABLEIWILLNEVERUSETHENAMEOF

MyVar[ E2_DATA1 ] = E_DATA1;
Код:
warning 221: label name "_" shadows tag name
Any help would be appreciated!
Reply
#2

Print takes only one strong tag - Float. You could try with weak tag: https://sampwiki.blast.hk/wiki/Scripting:tags#Weak_tags
Reply
#3

I will try - cheers
Reply
#4

pawn Код:
enum e_MY_ENUM
{
    E_DATA1,
    E_DATA2
};

enum E_MY_2ND_ENUM
{
    e_MY_ENUM:E2_DATA1,
    E2_DATA2
};

new
    MyVar[ E_MY_2ND_ENUM ]
;

main() {
    MyVar[ E2_DATA1 ] = E_DATA2;
    printf("We at @%d", MyVar[E2_DATA1]);
}
Reply
#5

- ignore -

Cheers.

For anyone wondering why I want this: I just simply find this a bit more systematic than making 89273489234 macros when assigning values

pawn Код:
// instead of doing this:
#define VAL1 (0)
#define VAL2 (1)

new
    MyVar[ MAX_PLAYERS ]
;

MyVar[ playerid ] = VAL1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)