Jump to content

How to store multiple boolean values in a binary string?


Recommended Posts

I need a binary variable to contain multiple Boolean values, I am not sure if it has to do the Bit function as I don't know much about them. I searched the forums to no avail, any help is very much appreciated as always, thank you.

Link to comment
Share on other sites

Sorry my description was vague, we are on the right path I believe though. =) How would I go about checking if just one specific value is true? Also how do I generate the $fDUmmy in your question? Sorry I am quite noob with these.

Edited by foster74
Link to comment
Share on other sites

You can have N flag for N bits variable, so 32 bit int for example contain 32 possible flags instead of declaring 32 boolean variables or 32 int in this matter.

I'll try to describe it better as I can:

; These are the properties you may want to determine if are set '1' or aren't '0':
Enum Step *2 $fVisible, $fShiny, $fTiny, $fDummy, $fLucky, $fStrike

; A variable that holds a few properties:
Dim $fVar = BitOR($fVisible, $fTiny, $fLucky, $fStrike)

; Checking each property, if a property set BitAND result in a value greater then 0, else, 0.
; Same as If BitAND($Var, $fProperty) > 0 Then ...:
If BitAND($fVar, $fVisible) Then ConsoleWrite('Visible is set' & @LF)
If BitAND($fVar, $fShiny) Then ConsoleWrite('Shiny is set' & @LF)
If BitAND($fVar, $fTiny) Then ConsoleWrite('Tiny is set' & @LF)
If BitAND($fVar, $fDummy) Then ConsoleWrite('Dummy is set' & @LF)
If BitAND($fVar, $fLucky) Then ConsoleWrite('Lucky is set' & @LF)
If BitAND($fVar, $fStrike) Then ConsoleWrite('Strike is set' & @LF)
Link to comment
Share on other sites

binary as in 1 0 1 0 0 1 1 0 1 1

Whatever works best, not sure, but had that in mind... But I'd prefer to use a single line of code to figure out if a certain value is 1 or 0 if possible. Like lets say;

Value1 = true

Value2 = false

Value3 = true

I'd like to keep these in a single string and use one line to check and/or modify the data. Such as:

If Value1 = true Then value1 = false.

I hope I'm not confusing anyone. =)

Link to comment
Share on other sites

Perfect example Authenticity, exactly what I was looking for, this will help me with storing and parsing data a ton! Thanks a million! =)

Edit: Oh a quick follow up question. What's the correct way to deselect a value?

If BitAND($fVar, $fTiny) Then $fVar -= $fTiny

Is what I am thinking, is there a better way?

Edited by foster74
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...