Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expanding SELECT CASE
#1
I've been trying to clean up IF statements in the game I'm working on. Would it be hard to have SELECT CASE work not just with variables but also with arrays and UDTs?

Imagine:
            SELECT CASE flag '        (booleans)
                CASE .drawShip: .........
                CASE .explode: .........
                CASE .endRound: .........
             END SELECT
Or:
            SELECT CASE fatArray()
                CASE 0 TO 50: ..............
                CASE 51 TO UBOUND(fatArray): ..........
            END SELECT

Would this be cool / useful?
Reply
#2
(10-20-2024, 06:08 PM)NakedApe Wrote: I've been trying to clean up IF statements in the game I'm working on. Would it be hard to have SELECT CASE work not just with variables but also with arrays and UDTs?

Imagine:
            SELECT CASE flag '        (booleans)
                CASE .drawShip: .........
                CASE .explode: .........
                CASE .endRound: .........
             END SELECT
Or:
            SELECT CASE fatArray()
                CASE 0 TO 50: ..............
                CASE 51 TO UBOUND(fatArray): ..........
            END SELECT

Would this be cool / useful?

I honestly don't see how either of these would work.   

CASE .drawship    <-- what does this represent?  

TYPE POINT
    x as long
    y as long
END TYPE

DIM User AS POINT, Enemy AS POINT

CASE .x    <-- by itself, this does nothing.   How could I tell the difference between User.x and Enemy.x?



And the second doesn't look like it's actually using the array either.  It looks more as if you're doing a select case with the index of the array:

SELECT CASE index
   CASE 0 TO 50
   CASE 51 TO UBOUND(Array)
END SELECT



I'm all for expanding things to make them more useful.  I just don't see how these would work in the cases you've provided.
Reply
#3
Yeh, I wasn't very clear. Let's say you're using a boatload of true/false flags to turn on and off various events, timers and subs (as I am). Instead of separately naming _byte variables for each flag (FLIP_ON_SHIP = TRUE,  START_GAME_TIMER = TRUE), let's say for organizing purposes you stick them all in UDTs (like I did), like 

Type FLAG

FLIP_ON_SHIP As _BYTE
START_GAME_TIMER As _BYTE
ETC.

End Type

It would be nice now to be able to use a SELECT EVERYCASE structure to tick through the booleans (in an array or UDT) and act on them instead of using a big bunch of IF statements. Or is there simply a better way to organize event flags for complicated programs?
Reply
#4
Why not just put them in an array and then enumerate through them?
Tread on those who tread on you

Reply
#5
Thanks, Sprigssy. I did use an array for sound flags just to mark them as played, but I guess I need an example.  How would I structure a Boolean flag in an array to then cause an action in the program? Use On x Gosub? Or what are you thinking. Thnx.
Reply
#6
Oh, I see. Duh. Something like this?

For c = 0 to Ubound(flag)
If flag(c) then
Select case c
-
End Select
End If
Next c

Loop u
Do 
C= C + 1
If flag(c) then
Select Case
-
End Select
End if
Loop until c = Ubound(flag)
Reply




Users browsing this thread: 5 Guest(s)