Inline If (IIF) ?

Previous topic - Next topic

bigtunacan

Is there some command in GLBasic similar to the Inline If provided in VB - IIF ?

Code (glbasic) Select

Public Function IIf( _
   ByVal Expression As Boolean, _
   ByVal TruePart As Object, _
   ByVal FalsePart As Object _
) As Object


It allows you to conditionally return 1 or other value inline.

Code (glbasic) Select

IIF(var=1,1,0) // If var equals one then substitute 1 here, otherwise substitute 0 here.


What I am trying to do is render a sprite that does conditional vertex blending.

Code (glbasic) Select

STARTPOLY 0,0 // Bitmap = No.0
   POLYVECTOR  x,    y,  txt_spr.tx1,  txt_spr.ty1, IIF(BLEND=1, RGB(R,G,B), RGB(255,255,255))
   POLYVECTOR  x, y+height, txt_spr.tx1, txt_spr.ty2, IIF(BLEND=2 RGB(R,G,B), RGB(255,255,255))
   POLYVECTOR  x+width, y+height, txt_spr.tx2, txt_spr.ty2, IIF(BLEND=3, RGB(R,G,B), RGB(255,255,255))
   POLYVECTOR  x+width, y, txt_spr.tx2, txt_spr.ty1, IIF(BLEND=4, RGB(R,G,B), RGB(255,255,255))
ENDPOLY

kanonet

There are several ways to do this, in your case I would think about this:

Code (glbasic) Select
FUNCTION IIF: condition, if_true, if_false
IF condition
RETURN if_true
ELSE
RETURN if_false
ENDIF
ENDFUNCTION

Not tested, but it should perfect fit your needs...
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

bigtunacan

Yes; I understand it is easy enough.  If there is something that already exists I prefer to use it.

Ruidesco

I think nothing like that exists right now, although it's a useful function to have for typing clean code.

Kitty Hello

ah. IIF is that command? I didn't know about it.
In C it's
expression ? true_value : false_value

I'll put that on the list.

bigtunacan

Yes IIF is common enough basic version of C's "expression ? true_value : false_value"