Help

BlitzMax Forums/BlitzMax Programming/Help

Sarge(Posted 2005) [#1]
Hi i was just wondering how i can do the following i have tryed it and had no luck

Function test( style:Int )

Local flag=0
Local a=1
Local b=2
Local c=3

Select style

Case fast
flag=flag|a
Case tall
flag=flag|b
Case big
flag=falg|c
End Select

Print flag

End Function

test( fast | tall )

Now what this is supposed to do is return Fast + Small by using |

Ok this is just a example that i just made up but you get the idea hopefully, any help will be good thanks.


Koekelas(Posted 2005) [#2]
I could be wrong so if I am, ignore my post. Isn't | a logical operator? So a | b would return a, b or ab but not a + b.


Nicolas.


Paul "Taiphoz"(Posted 2005) [#3]
I think Nicolas is right, without reading the docs it looks like a logical op..

I think to do what your trying you will have to use a tokened string. like return a+"/"+b if a was fast and b was big it would return "fast/big" you then where needed just split the string up based on the "/" token..

I may be wrong tho and I'm sure others will have much faster better ways of doing it.


Sarge(Posted 2005) [#4]
nuh i am using it for my gui to do, example for font Bold | Underline

Any other help please ?


Perturbatio(Posted 2005) [#5]
I can see a typo:
flag=falg|c



Sarge(Posted 2005) [#6]
As i said that was just a example i just made up.

Thanks for you help guys


Who was John Galt?(Posted 2005) [#7]
You need to set uo some consts for fast, tall etc. If flag is fast|tall, it won't equal fast and it wont equal tall. You can do something like this:

const fast=1
const tall=2
const big=4

flag=big|fast

If flag&fast
print("flag is fast");
endif
if flag&big
print("flag is big");
endif


This is untested. Your consts have to be powers of 2 - 1,2,4,8 etc.


Koekelas(Posted 2005) [#8]
It's just an idea.

Local a:Int	= 1
Local b:Int	= 2

aFunction(Int(String(a) + String(b)))

Function aFunction(aNumber:Int)
	
	'Do something with aNumber
EndFunction


In this example aNumber would be 12 and if I'm not mistaking this is what your looking for.


Nicolas.


Sarge(Posted 2005) [#9]
Falken, thanks mate i just have to go with the IF/EndIf

Nicolas De Jaeghere, nuh thats not exactly what i needed but its a very nice example thank you