How work the | operator on passed parameters?
BlitzMax Forums/BlitzMax Programming/How work the | operator on passed parameters?
| ||
Hi here with another question. I have some constant Const A:Int = 1 Const B:Int = 2 Const C:Int = 3 Const D:Int = 4 And a function passParams() end Function I want to pass parameters like: passParams(A|B|C) And inside the function want to check if the pass params contains the A value and make a specific thing, if passed B make other thing .... Some one can tell me how to code it? Thanks. |
| ||
Sure, but you won't be able to use 1,2,3 and 4 as you've done in your example. If you did that, there would be no way to determine if I chose flag C or Flags A and B, since both would equal three. For bit flags, which is what you're really doing here, you need to use powers of two only. You also need to use the & (AND) operator to determine which flags are set. Const A:Int = 1 Const B:Int = 2 Const C:Int = 4 Const D:Int = 8 Function passParams(Flags:Int) If Flags&A Print "Flag A:True" Else Print "Flag A:False" End If If Flags&B Print "Flag B:True" Else Print "Flag B:False" End If If Flags&C Print "Flag C:True" Else Print "Flag C:False" End If If Flags&D Print "Flag D:True" Else Print "Flag D:False" End If End Function passParams(A|B|C) passParams(D|C) |
| ||
Really thanks Grabriel I solve my problem. |