SA-MP Forums Archive
Enum as value of a function - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Enum as value of a function (/showthread.php?tid=424036)



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

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

pawn Код:
values[value1]



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

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.


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
Посмотреть сообщение
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.
}



Re: Enum as value of a function - Misiur - 20.03.2013

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