% fellowed by number ?

Monkey Forums/Monkey Programming/% fellowed by number ?

Rushino(Posted 2012) [#1]
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!


Jesse(Posted 2012) [#2]
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.


Rushino(Posted 2012) [#3]
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! :)


Jesse(Posted 2012) [#4]
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.


Rushino(Posted 2012) [#5]
Yeah.. it seem interesting also when it come to saving and loading data. Alright thanks!


Jesse(Posted 2012) [#6]
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




Rushino(Posted 2012) [#7]
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 :)


Jesse(Posted 2012) [#8]
not just what I meant

[edit]

sorry I didn't see my mistake.