Java If to Blitzmax
BlitzMax Forums/BlitzMax Programming/Java If to Blitzmax
| ||
java code: x2 = x1 + SCREEN_WIDTH + (x1 == 0 ? 0 : TILE_SIZE); Hello, What is the best way to convert this to Blitzmax..? This code has an embedded if/then.. Thanks, FBEpyon |
| ||
There are not this inmediate if operators in BMIf X1=0 then x2 = x1 + SCREEN_WIDTH Else x2 = x1 + SCREEN_WIDTH + TILE_SIZE Endif Maybe eaiser: x2 = x1 + SCREEN_WIDTH if x1<>0 then x2 += TILE_SIZE |
| ||
Thank you.. I know it was easy, but I'm not having a very good week lol Thanks Again!! |
| ||
If you don't care about readability, you can multiply each result of that ternary operation by the equivalent boolean operation, which in BlitzMax results in 0 or 1. x2 = x1 + SCREEN_WIDTH + (x1 == 0 ? 0 : TILE_SIZE); Becomes... x2 = x1 + SCREEN_WIDTH + ( 0 * ( x1 = 0 ) ) + ( TILE_SIZE * ( x1 <> 0 ) ) (You can remove the first boolean operation since it will always evaluate to 'zero'. I just added it for completeness.) |
| ||
x2 = x1 + SCREEN_WIDTH + IfThenElse(x1 = 0, 0, TILE_SIZE) Function IfThenElse( Condition, IfTrue, IfFalse ) If Condition Then Return IfTrue Else Return IfFalse End Function |