Enum as value of a function
#1

Hi, I'm making a function to simplify a little the code. But the function needs to send a value from an enum.

I'll explain with examples:

pawn Код:
enum MyEnum
{
    value1,
    value2,
    value3
}

stock MyFunction(playerid, value)
{
    if (value == value1)
        SendClientMessage(playerid, 0xFFFFFFFF, "It works!");
}

MyFunction(playerid, value1); // Will give error 091: ambiguous constant; tag override is required (symbol "value1")
How could I do that?

Thanks you in advance.
Greetings.
Reply
#2

Enums need to be defined by using

pawn Код:
new values[MyEnum];
Then you can use

pawn Код:
values[value1]
Reply
#3

No, they don't

pawn Код:
stock MyFunction(playerid, MyEnum:value)
(MyEnum is strong tag in this case)
Error is about something else, you might have 2 enums with same constants, you have to provide tag then as well
Reply
#4

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Enums need to be defined by using

pawn Код:
new values[MyEnum];
Then you can use

pawn Код:
values[value1]

I know that, but the problem is that I can't use this way because I need to parse this value to another variable.

Example:

pawn Код:
enum MyEnum
{
    value1,
    value2,
    value3
}

new MyVariable[MAX_PLAYERS][MyEnum];

stock MyFunction(playerid, value)
{
    MyVariable[playerid][value];
    SendClientMessage(playerid, 0xFFFFFFFF, "It works!");
}

MyFunction(playerid, value1); // Will give error 091: ambiguous constant; tag override is required (symbol "value1")
Thanks you.
Reply
#5

Quote:
Originally Posted by Misiur
Посмотреть сообщение
No, they don't

pawn Код:
stock MyFunction(playerid, MyEnum:value)
(MyEnum is strong tag in this case)
Error is about something else, you might have 2 enums with same constants, you have to provide tag then as well
I don't understand you at all.

With your way still the same error.
Look at my previous post please.

Thanks you.
Reply
#6

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Error is about something else, you might have 2 enums with same constants, you have to provide tag then as well
Damn, I'm quoting myself.

Take a look at this code:

pawn Код:
enum E_1 {
    beer,
    value1
}

enum E_2 {
    Float:waffle = 5,
    value1
}

printf("Value of value1 is %d", value1);
You will get ambiguous constant error. Compiler doesn't know which one to use. You have to do
pawn Код:
printf("Value of value1 is %d", E_1:value1); //returns 1
//Or
printf("Value of value1 is %d", E_2:value1); //returns 6
In your case

pawn Код:
MyFunction(playerid, MyEnum:value1)
Reply
#7

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Damn, I'm quoting myself.

Take a look at this code:

pawn Код:
enum E_1 {
    beer,
    value1
}

enum E_2 {
    Float:waffle = 5,
    value1
}

printf("Value of value1 is %d", value1);
You will get ambiguous constant error. Compiler doesn't know which one to use. You have to do
pawn Код:
printf("Value of value1 is %d", E_1:value1); //returns 1
//Or
printf("Value of value1 is %d", E_2:value1); //returns 6
In your case

pawn Код:
MyFunction(playerid, MyEnum:value1)
Excuse me but It still giving that error and tag mismatchs.

What I did:

pawn Код:
enum MyEnum
{
    value1,
    value2,
    value3
}

new MyVariable[MAX_PLAYERS][MyEnum];

stock MyFunction(playerid, value)
{
    MyVariable[playerid][value];
    SendClientMessage(playerid, 0xFFFFFFFF, "It works!");
}

MyFunction(playerid, MyEnum:value1);
Thanks you a lot.
Reply
#8

http://forum.sa-mp.com/showpost.php?...33&postcount=3
Compare this to your function definition, add the missing tag and voilа
Reply
#9

Quote:
Originally Posted by Misiur
Посмотреть сообщение
http://forum.sa-mp.com/showpost.php?...33&postcount=3
Compare this to your function definition, add the missing tag and voilа
Ok, it worked. Now, I have a little trouble:

I have a swicht and I can't set the cases because of the ":" symbol.

There is another way to do it or I must use "if"?

pawn Код:
switch (value)
{
    case MyEnum:value1: {} // Can't do that.
}
Reply
#10

pawn Код:
switch (value)
{
    case (MyEnum:value1): {}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)