Log in

View Full Version : enumerated constants



NeoPhoenix
03-14-2012, 02:27 PM
hi

i wanted to know how to use enumerated constants. all i know about is:
const tagname: //"tagname:" is optional
{
const_1 = 0,
const_2,
const_3
}
the subsequent constants are automatically assigned as preconstant+1 (const_1 = 0, const_2 = 1, const_3 = 2) but i want to use other increment values. for exapmle
enum tagname (<<=1)
{
const_1 = 1,
const_2,
const_3
}
the subsequent constants are now assigned as preconstant shifted 1 bit left. (const_1 = 0b001, const_2 = 0b010, const_3 = 0b100).

anyone know how to manage that since the "enum" was removed?

foxtacles
03-14-2012, 08:58 PM
I haven't worked with the new version of PAWN myself, but a quick look at the new language guide reveals that it should be still possible to override the default increment value of 1:

https://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
(page 101)

I don't know the syntax though. I'd assume it's similar to that of the old PAWN version with enum.

NeoPhoenix
03-14-2012, 10:13 PM
i have already read that guide but there is still no example for that case :/

Lorenc
03-26-2012, 11:06 AM
const E_RANDOM_ENUM: (<<=1) // I think you need the colon there ^.^
{
const_1 = 1,
const_2,
const_3
};

new
g_enumData[ E_RANDOM_ENUM ]
;

//Usage
g_enumData[ const_1 ] += 5;
g_enumData[ const_2 ] += 6;
g_enumData[ const_3 ] += 7;


Can you elaborate?

NeoPhoenix
03-26-2012, 02:10 PM
Nope it gives me
error 020: invalid symbol name ""
Line:
const E_RANDOM_ENUM: (<<=1)

//Edit:
@Lorenc_: For those arrays (often used in sa:mp scripting like PlayerInfo) you can use tags. for example
new PlayerInfo[20][
.name[20],
Float:.pos[3],
bool:.connected];

Lorenc
04-09-2012, 01:11 PM
enum/constants are more neat, that piece looks so ugly lol.

NeoPhoenix
04-09-2012, 01:16 PM
im not sure if you can use that constants in a way like in sa:mp. enumerators have been removed and those constants are not like enums in an older version of pawn

Aeronix
04-30-2012, 11:15 PM
Well to be honest, enumerators in the new version seem like a bunch of constants to me in an array.
The syntax would probably be different for your understanding.
Have you downloaded the latest PAWN version?