Log In  

When calling fget without a flag index, how can you translate
the bitfield returned by fget back into it's respective flag index (0-7)?

P#138115 2023-12-01 21:03

3
flags=fget(sprite_index)
flag_0=(flags & 1 != 0)
flag_1=(flags & 2 != 0)
flag_2=(flags & 4 != 0)
flag_3=(flags & 8 != 0)
flag_4=(flags & 16 != 0)
flag_5=(flags & 32 != 0)
flag_6=(flags & 64 != 0)
flag_7=(flags & 128 != 0)
n=3
flag_n=(flags & (1<<n) !=0)

@Bee_Randon Note that a sprite can have any and all of the eight flags, so there's really no getting the index of "THE" flag since it's not necessary unique.
If for some reason your sprites all have exactly one flag, use a lookup table with the 8 possible values.

P#138116 2023-12-01 21:20 ( Edited 2023-12-01 21:39)

worth noting that the button symbols are tied to the index of their bit flags, so for example (btn()&(1<<🅾️))!=0 is roughly equivalent to btn(🅾️) (I believe)

P#138158 2023-12-02 19:02

the question is about fget bitfield, not btn bitfield :)

P#138198 2023-12-03 22:35

d'oh! right you are ;)

P#138214 2023-12-04 06:11

[Please log in to post a comment]