Enum as value of a function -
luis_lpv_22 - 20.03.2013
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.
Re: Enum as value of a function -
SuperViper - 20.03.2013
Enums need to be defined by using
Then you can use
Re: Enum as value of a function -
Misiur - 20.03.2013
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
Respuesta: Enum as value of a function -
luis_lpv_22 - 20.03.2013
Quote:
Originally Posted by SuperViper
Enums need to be defined by using
Then you can use
|
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.
Respuesta: Re: Enum as value of a function -
luis_lpv_22 - 20.03.2013
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.
Re: Enum as value of a function -
Misiur - 20.03.2013
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)
Respuesta: Re: Enum as value of a function -
luis_lpv_22 - 20.03.2013
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.
Re: Enum as value of a function -
Misiur - 20.03.2013
http://forum.sa-mp.com/showpost.php?...33&postcount=3
Compare this to your function definition, add the missing tag and voilа
Respuesta: Re: Enum as value of a function -
luis_lpv_22 - 20.03.2013
Quote:
Originally Posted by Misiur
|
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.
}
Re: Enum as value of a function -
Misiur - 20.03.2013
pawn Код:
switch (value)
{
case (MyEnum:value1): {}
}