Thought this object could be quite handy, and reasonably simple to develop. A similar one already existed for MMF1.5:
A Bit Object for handling individual bits in a value (I think it was called the Bit Mask Object).
It would have the following features:
Bit Masking
Taking a value, and changing its bits using a masking string. EG:
changeBits("BMO", 32, "110--t--")
BMO is the name of the object.
This would take the value '32' (00100000) and convert it using the bit mask "110--t--"
In the mask, the possible characters are:
0 = force this bit to '0'
1 = force this bit to '1'
t = toggle this bit. So 1 becomes 0 and 0 becomes 1.
- = leave this bit as it is.
So the result would be 11000100 (196).
It could be useful for storing flags in objects that may not inherently handle flags, since it's just one number. You could also pass traits on to other objects easily. For example, suppose you had a game where an object has a series of flags, and when it shoots another object, the flags it has are passed on to its opponent. This could be done by copying just one value, instead of loads of individual flags.
You could also organise flags in alterable values, thereby giving them names. So a set of flags named 'Conversations' and 'Inventory data' and 'Level Settings' etc.
It could have a few settings that could be altered at runtime, such as:
- Left/Right aligned (e.g. if we have a 32 bit '0' and we have a mask of '011' (only 3 digits), LEFT align gives '01100000' and RIGHT align gives '00000011')
- Reverse value (e.g. a value like 217 (11011001) would become 155 (10011011). Literally the bits go from abcdefgh to hgfedcba)
It could potentially have a slightly more complex markup like this if people thought it might be useful, by adding a few more characters:
' = start a statement
* = repeat the statement to the end
eg:
1* = 11111111 (1 repeated in all further bits)
'10* = 10101010 (10 repeated in all further bits)
111'10* = 11110101 (111, then 10 repeated afterwards)
10*101 = 10101101 (10 repeated until the last three digits, which are 101)
Can't think of a use for the additional statements above, but the rest would be very handy.
Bit Blending with Mask
This would allow two values to be blended with a mask, e.g.
bitblend("BMO", 255, 217, "aox01fL0")
a = ADD
o = OR
x = XOR
0 = always a 0
1 = always a 1
f = the bit from the FIRST value
L = the bit from the LAST value




Reply With Quote






