Expanding SELECT CASE - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +---- Forum: GitHub Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=42) +---- Thread: Expanding SELECT CASE (/showthread.php?tid=3144) |
Expanding SELECT CASE - NakedApe - 10-20-2024 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? RE: Expanding SELECT CASE - SMcNeill - 10-20-2024 (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? 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. RE: Expanding SELECT CASE - NakedApe - 10-20-2024 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? RE: Expanding SELECT CASE - SpriggsySpriggs - 10-24-2024 Why not just put them in an array and then enumerate through them? RE: Expanding SELECT CASE - NakedApe - 10-24-2024 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. RE: Expanding SELECT CASE - NakedApe - 10-24-2024 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) |