variant constants

Blitz3D Forums/Blitz3D Beginners Area/variant constants

stayne(Posted 2008) [#1]
Const item0 = %0000000001
Const item1 = %0000000010
Const item2 = %0000000100
Const item3 = %0000001000
Const item4 = %0000010000
Const item5 = %0000100000
Const item6 = %0001000000
Const item7 = %0010000000
Const item8 = %0100000000
Const item9 = %1000000000

What comes next? I have many other items I need to add to the fray. %10000000001, %1000000010, etc doesn't seem to work.


Ross C(Posted 2008) [#2]
Const item0 = %0000000001

Const item0 = 1

Strange way to write it :o) Why have you put the zero's in front? It looks like your trying to use bits here. But surely blitz would save 0000000001 as 1, as % is an interger variable is it not?


stayne(Posted 2008) [#3]
Trying to get my head around morduun's inventory code...




Stevie G(Posted 2008) [#4]
Mordunns system is more like binary flags , so looks like this in int form.

Const ITEM_HEAD =  1		; generally caps & helms
Const ITEM_NECK =  2		; generally amulets/necklaces
Const ITEM_BACK =  4		; generally cloaks
Const ITEM_QUVR =  8
Const ITEM_LHAND = 16		; generally shields
Const ITEM_RHAND = 32		; generally weapons
Const ITEM_BHAND = 64		; generally gauntlets & 
const 
gloves
etc..


This flag is basically 2^( Item property ) so that you can store and access multiple properties for each object. You would assign this property to the item rather than item0 = 1, item 1 = 2 , item 2 = 4 etc.. I think you misunderstand it's usage.

So, for example if you have a sword which you can hold in your Left Hand and Right Hand you would set the item property flag to 96 ( 32 + 64 )

When checking which slots this item can be placed ...

Flag = 32+64

if Flag and ITEM_LHAND
  { this item can be held in the left hand }
endif

if Flag and ITEM_RHAND
  { this item can be held in the right hand }
endif


Both conditions will return true so the system knows it can be placed in either slot.

Another example, level ambience :

;level ambience
;time of day
Const LA_DAY = 1
Const LA_NIGHT = 2
;weather
Const LA_MILD = 4
Const LA_SUN = 8
Const LA_RAIN = 16
Const LA_FOG = 32
Const LA_WIND = 64
Const LA_THUNDER = 128


So to set a the ambience to night + raining + thunder ..

global LA_FLAG = LA_NIGHT + LA_RAIN + LA_THUNDER


To access the individual properties ..
If ( LA_FLAG and LA_NIGHT )
   ;turn the lights out
endif

if ( LA_FLAG and LA_RAIN )
   ;make it rain
endif


Not much of an explanation but hopefully it'll help slightly.

Stevie


stayne(Posted 2008) [#5]
Makes perfect sense, thanks a ton. I pretty much figured things out by the time I read this and it works great. Thank goodness for people that donate code (morduun).