Main Menu

Bit flags?

Started by Draco9898, January 21, 2005, 09:11:17 PM

Previous topic - Next topic

Draco9898

I was wondering if we could please see an example of a bit flag so we dont have to have so many differrent varibles for our games characters, I.E:

Player.Walking, Player.Ducking, Player.Sitting, when you could just turn it into one varible with different combinations of numbers? I.E: Player.Status

ya know what I mean? Thanks :)
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

Draco9898

Ahhh Nevermind I think I figured it out, you can assign different 'modes' different powers of 2.

I.E: Ducking= 2, Waving=4, Begging=8


Then if two were on at a time you get different values, I.E:

Ducking + Waving = 6 ;  Ducking+Begging=10

Waving+Begging=12


Then If all three we're on:

Ducking + Waving+Begging=14


So I guess you'd have to make a table and remember what values were each :)
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#2
PlayBASIC Code: [Select]
; Create BIT constants.. pre calc 
Acset = 0
Constant Bit0 = 2^ac(1)
Constant Bit1 = 2^ac(1)
Constant Bit2 = 2^ac(1)
Constant Bit3 = 2^ac(1)
Constant Bit4 = 2^ac(1)
Constant Bit5 = 2^ac(1)
Constant Bit6 = 2^ac(1)
Constant Bit7 = 2^ac(1)

print Bit0
print Bit1
print Bit2
print Bit3
print Bit4
print Bit5
print Bit6
print Bit7


print Bin$(Bit0)
print Bin$(Bit1)
print Bin$(Bit2)
print Bin$(Bit3)
print Bin$(Bit4)
print Bin$(Bit5)
print Bin$(Bit6)
print Bin$(Bit7)

sync
waitkey






Draco9898

DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin