% fellowed by number ?
Monkey Forums/Monkey Programming/% fellowed by number ?
| ||
Hello, I was looking at an Ignition example and i was wondering what mean. Const MONKEY_JUMPING = %1 Const MONKEY_FALLING = %10 They seem to be flags from what im understanding but what %1 and %10 mean ? It is a representation in binary of a decimal ? It seem i can't find anything in the doc regarding this ! Thanks! |
| ||
Yes, It means binary: %1 = 1 %10 = 2 %100 = 4 %110 = 6 %111 = 7 you can use up to 32 valid bits in all platforms but some platforms accept 64 bits. |
| ||
Thanks for the clarification. Just wondering.. cause im coming from a web application world so it is generally common to use int to define flags ? What are the benefits ? Thanks again! :) |
| ||
you can use what ever you want. but a lot of folks use binary integer flags because individual flags can be combined with multiple flags in a single integer. |
| ||
Yeah.. it seem interesting also when it come to saving and loading data. Alright thanks! |
| ||
little snippet:const big:int = %100 const fat:int = %010 const blond:int = %001 const playerStatus:int = %101 if (playerStatus & big) Print "player is Big" if (playerStatus & fat) Print "player is fat" if (playerStatus & blond) Print "Player is blond" code should Print: player is Big player is blond |
| ||
You meant ? const big:int = %100 (instead of 001?) const fat:int = %010 const blond:int = %001 Anyway thanks for your sample, i see the point now :) |
| ||
[edit] sorry I didn't see my mistake. |