Parameters in the enum 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)
+---- Forum: Discussion (
https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Parameters in the enum function (
/showthread.php?tid=634216)
Parameters in the enum function -
NguoiChauA - 15.05.2017
I'm learning about Pawn language . I'm having trouble with parameters in the enum function
enum E_MY_TAG (<<= 1)
{
E_MY_TAG_NONE,
E_MY_TAG_VAL_1 = 1,
E_MY_TAG_VAL_2,
E_MY_TAG_VAL_3,
E_MY_TAG_VAL_4
}
new E_MY_TAG:gMyTagVar = E_MY_TAG_VAL_2 | E_MY_TAG_VAL_3;
I learned that the values in the enum will increment by default by +=1 and my lesson says the code :
new E_MY_TAG:gMyTagVar = E_MY_TAG_VAL_2 | E_MY_TAG_VAL_3;
That will create a new variable and assign it the value 6 (4 | 2)
I don't understand it , why the value of E_MY_TAG_VAL_2 is 4 and E_MY_TAG_VAL_3 is 2 and the parameter in the enum function why it is <<=1 , i remember there is no such operator . Thank you ^^
Re: Parameters in the enum function -
Aviicix - 16.05.2017
The operator "<<" it's a bitwise shift operator, the code you posted is used to make "Bit Flags"
PHP код:
enum E_MY_TAG (<<= 1)
{
E_MY_TAG_NONE, //0b00000000000000000000000000000000 = 0
E_MY_TAG_VAL_1 = 1, //0b00000000000000000000000000000001 = 1
E_MY_TAG_VAL_2, //0b00000000000000000000000000000010 = 2
E_MY_TAG_VAL_3, //0b00000000000000000000000000000100 = 4
E_MY_TAG_VAL_4 //0b00000000000000000000000000001000 = 8
}
If you want to learn more about bit flags check this topic:
https://sampforum.blast.hk/showthread.php?tid=216730