? : syntax

Blitz3D Forums/Blitz3D Beginners Area/? : syntax

ryan scott(Posted 2006) [#1]
i can't remember and can't find anywhere how to use this syntax:

e\rotyspeed# = (Rand(0,1) = 1) ? -3:3

I'm looking for rand to return 0 or 1, and i translate that into -3 or 3

clues for the clueless?


Rob Farley(Posted 2006) [#2]
As far as I'm aware it doesn't exist in blitz however...
x = ((Rand(0,1) * 2) - 1) * 3

explained...
(0 or 1) * 2 = (0 or 2) - 1 = (-1 or 1) * 3 = (-3 or 3)

That said... I'm not sure if it's going to be faster to just do
if rand(0,1) then x=3 else x=-3


octothorpe(Posted 2006) [#3]
There is no ternary operator in B3d; that said, there's no reason why you can't create your own function to accomplish the same thing.


ryan scott(Posted 2006) [#4]
ugh

could have sworn it had it.

thanks guys


Floyd(Posted 2006) [#5]
e\rotyspeed# = 6*Rand(0,1) - 3


Sir Gak(Posted 2006) [#6]
@Floyd's solution is good.


Warren(Posted 2006) [#7]
Unrelated to the actual question asked but it will work, yes.


Sir Gak(Posted 2006) [#8]
I'm looking for rand to return 0 or 1, and i translate that into -3 or 3

@WarrenM: How is it unrelated to the original question (quoted above)? Floyd's solution answers the question precisely and well-done, at that.