Here is a little commented snippet that shows how to create a menu with one variable and an array. It may come in helpful, as it would save you from using lots of if/endif's for each menu item. It works in DBPro and should work in DBC.
rem ****************************************
rem ****************************************
rem ARRAY MENU SNIPPET: BY SIXTY SQUARES *
rem ****************************************
rem ****************************************
rem Setup the demo
sync on
sync rate 60
rem Set the number of menu items to be 3.
NumOfItems=3
rem Create an array to hold our menu items. We will have 3 items (as stated in NumOfItems), each is a string.
DIM MenuItems$(NumOfItems)
rem Now, we make the first item be "NEW GAME".
MenuItems$(1)="NEW GAME"
rem Our Second item will be "LOAD GAME".
MenuItems$(2)="LOAD GAME"
rem Our third item will be "QUIT GAME"
MenuItems$(3)="QUIT GAME"
rem Now, to begin out loop using a repeat and until loop. These are like do-loop but they will end when a certain event occurs.
repeat
rem Assume that the player's mouse is not over any item right now. If we are wrong and the player HAS selected an item, this variable will be changed.
Item=0
rem Clear the screen of any text.
cls
rem Begin a For-next loop checking each menu item
For i = 1 to NumOfItems
rem We can set the ink color to white to begin with. If the item is selected it will change to red later.
ink rgb(255,255,255),0
rem Now, check to see if the mouse is in range of the text.
rem First, we shall see if the mouse is further than 0 on the x axis.
if mousex()>0
rem Now, we check to see if it is less than the width of the text in the current item chosen by our for-next loop.
if Mousex()<Text Width( MenuItems$(i) )
rem Now, we shall check to see if the mouse if further than where the text begins vertically (on the Y axis).
rem We use i*20 because that's where the text will be: it's location in the menu separated by 20. In our for-next loop, i is the current menu item, as it
rem cycles through each menu item.
if Mousey()>i*20
rem Now, let's see if it is less than the vertical height of the text.
if mousey()<i*20+Text Height( MenuItems$(i) )
rem If ALL of that is true, then we can make the text appear red.
INK RGB(255,0,0),0
rem Now, because ALL of that is true, this item MUST be the item that the player's mouse is over! So, we store that in a variable called "Item"
Item=i
rem Now, we have to end all of our if statements!
endif
endif
endif
endif
rem NOTE: This could have been done using the AND statement to make it shorter. I just layed it out for you.
rem Now we can print the menu's text using the current ink color, which was changed in that long statement of if's and endif's.
Text 0 , i*20 , MenuItems$(i)
rem By now we should know what item the player has selected, if any.
next i
rem Update our screen
sync
rem Keep on going until the user clicks the mouse and their choice is greater than 0 (meaning that they clicked on something).
rem Remember that the item that they clicked on is stored in the variable called "Item"
until mouseclick()=1 and Item>0
rem Clear the scren of text and set the ink color to green
cls
ink rgb(0,255,0),0
rem Now, time to test and see which item was clicked on. This is where the actions would go.
rem If it was Menu Item 1 (That's NEW GAME) then print "Hey, you clicked New Game!" and wait for the player to press a key.
rem NOTE: These could be replaced with any action, it does not have to be print.
if Item=1 then sync : print "Hey, you clicked New Game!" : sync : suspend for key
rem If it was Menu Item 2 (That's LOAD GAME) then print "You just clicked Load Game!" and wait for the player to press a key.
if Item=2 then sync : print "You just clicked Load Game!" : sync : suspend for key
rem If it was Menu Item 3 (That's "QUIT GAME") then print "That was Quit Game you clicked"
If Item=3 then sync : print "That was Quit Game you clicked!" : sync : suspend for key
rem Now, END the program
end
WAY shorter optimized version with no comments:
sync on
sync rate 60
NumOfItems=3
DIM MenuItems$(NumOfItems)
MenuItems$(1)="NEW GAME"
MenuItems$(2)="LOAD GAME"
MenuItems$(3)="QUIT GAME"
repeat
Item=0
cls
For i = 1 to NumOfItems
ink rgb(255,255,255),0
if mousex()>0 and Mousex()<Text Width( MenuItems$(i) ) and Mousey()>i*20 and mousey()<i*20+Text Height( MenuItems$(i) ) then INK RGB(255,0,0),0 : Item=i
Text 0 , i*20 , MenuItems$(i)
next i
sync
until mouseclick()=1 and Item>0
cls
ink rgb(0,255,0),0
if Item=1 then sync : print "Hey, you clicked New Game!" : sync : suspend for key
if Item=2 then sync : print "You just clicked Load Game!" : sync : suspend for key
If Item=3 then sync : print "That was Quit Game you clicked!" : sync : suspend for key
end
And uncommented with the text in the center of the screen:
sync on
sync rate 60
NumOfItems=3
DIM MenuItems$(NumOfItems)
MenuItems$(1)="NEW GAME"
MenuItems$(2)="LOAD GAME"
MenuItems$(3)="QUIT GAME"
repeat
Item=0
cls
For i = 1 to NumOfItems
ink rgb(255,255,255),0
if mousex()>Screen width()/2-Text Width( MenuItems$(i) )/2 and Mousex()<Screen width()/2+Text Width( MenuItems$(i) )/2 and Mousey()>i*20 and mousey()<i*20+Text Height( MenuItems$(i) ) then INK RGB(255,0,0),0 : Item=i
Center Text Screen width()/2 , i*20 , MenuItems$(i)
next i
sync
until mouseclick()=1 and Item>0
cls
ink rgb(0,255,0),0
if Item=1 then sync : print "Hey, you clicked New Game!" : sync : suspend for key
if Item=2 then sync : print "You just clicked Load Game!" : sync : suspend for key
If Item=3 then sync : print "That was Quit Game you clicked!" : sync : suspend for key
end
Any comments?