Jump to content
IGNORED

Are switch statements (or something similar) possible?


RetroFiends

Recommended Posts

EDIT: Disregard, should have waited for my coffee to kick in, I can use on... goto... and have multiples point to the same label. Oops :)

 

I can get close to this using on... goto..., but that requires some level of linearity to work.

I've finally come back to batari basic after a small break, and I've learned about switch statements and am now sorely missing them.

My level screens are stored in what is effectively a 2D array (using variable D, +-1 for up/down, +-10 for left and right), upon checking what screen you are on, it loads the corresponding walls for that room, from 0 to 99.
Before this re-haul, on... goto... was perfect, as it could simply jump to the room necessary. However, since every wall (north, south, east and west) is ultimately only one of two states, open or closed, I figure I'd save a lot of room by sharing them.

 

I could still use on... goto... if those labels then redirect to the appropriate wall state label, but I wonder if there's a better way. My first thought was just to string a bunch of OR statements but batari basic limits this to only one per statement. I suppose even still, I can use OR to cut the lines needed in half to do this, but this probably gets messy really fast. Any thoughts?

Edited by RetroFiends
Link to comment
Share on other sites

I take it you're using a different routine for each room? You may not need to do that. If the rooms are basically identical except for the walls, then you could define some arrays for the wall states. And if there are only two states for each wall, it could be a binary array (1 bit per wall). This could be done two different ways:

 

(1) Use one array, one byte per room. That gives you 8 bits to use for flags for each room. You could use 4 of the bits for the walls, leaving the other 4 bits for something else, like one 0-15 variable, or two 0-3 variables, or whatever, such as an index for a color table, or flags that indicate whether or not the room contains special objects or features (stairs up, stairs down, a trap, or treasure).

 

(2) Use four arrays, one bit per room. That is, one array would be for the north wall, another array for the east wall, another for south, and another for west. Then you'd need to extract the correct bit for the room using a formula, since each byte of an array would hold 8 rooms' worth of data, so you'd need to divide the room number by 8 to get the array index, and use the remainder to determine which bit to look at.

 

Either way, you'd just have a single routine to handle all of the rooms, and when you change rooms the routine would just retrieve the walls data from the array(s) and then redraw the screen as needed.

Edited by SeaGtGruff
Link to comment
Share on other sites

I'm already one step ahead of you, there. I'm already doing the game by an on-wall basis, and I already have an array which handles the rooms.
I have my walls set as such

 rem up

 rem closed
 if !w{0} then var1 = %11111111 : var2 = %11111111 : var5 = %11111111 : var6 = %11111111 

 rem open
 if w{0} then var1 = %00111111 : var2 = %00111111 : var5 = %00111111 : var6 = %00111111 

 rem right

 rem closed
 if !w{1} then var19 = %11000000 : var23 = %11000000 : var27 = %11000000

 rem open
 if w{1} then var19 = %00000000 : var23 = %00000000 : var27 = %00000000

 rem down

 rem closed
 if !w{2} then var37 = %11111111 : var38 = %11111111 : var41 = %11111111 : var42 = %11111111  

 rem open
 if w{2} then var37 = %00111111 : var38 = %00111111 : var41 = %00111111 : var42 = %00111111 

 rem left

 rem closed
 if !w{3} then var16 = %11000000 : var20 = %11000000 : var24 = %11000000 

 rem open
 if w{3} then var16 = %00000000 : var20 = %00000000 : var24 = %00000000 
 return otherbank

However, I could have up to 99 rooms, potentially.

I don't think it would be very efficient to do 99 if... then... statements. Whenever you enter a new room, the room variable will update, and then it will need to tell me what w{0-3} is, so this routine can run to update the walls.

Edit: On a side note, I might be able to combine the open and close variables into one line with an else...

Edited by RetroFiends
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...