Return values from functions in SWITCH expression

Previous topic - Next topic

MrTAToad

I did mention this ages ago, and I thought it might be worth bringing it up again to see if it's now possible to fix  =D

Some functions cannot be used in SWITCH expressions (and return a value that CASE statements dont usually detect).  For example :

Code (glbasic) Select
SELECT self.players[currentPlayer%].DoMove(self.setup,self.players[],self.board)
CASE PLAYER_MOVE% // Player has moved
gameState%=STATE_PROCESSEXPLOSIONS%

        CASE PLAYER_USESPECIALWEAPON% // Player has used an special weapon so process
gameState%=STATE_PROCESSSPECIALWEAPON%
ENDSELECT


With this example, neither CASE statements are executed unless a simple variable is used with the SELECT statement.

However, with this one :


Code (glbasic) Select
SELECT players[playerIndex%].ReturnSpecialWeaponSprite()
CASE SPRITE_DISINTEGRATOR% // Destroy whatever is on the tile
self.ClearGridLocation(self.toBeProcessed[0].x%,self.toBeProcessed[0].y%)
ENDSELECT


the correct CASE statement is executed.

Kitty Hello

I "think", that the expression in the SELECT is executed for every CASE. Must check the C++ code generated. That would be bad in some situations.