Good job Daygamer, I'm going over your code now.
You don't need to update newmouse and oldmouse in every statement, just stick it in the main loop.
rem menu
rem daygamer
rem Oct 24
menu=0
game_started=0
rem main loop
do
rem ** INPUT **
oldmouse = newmouse
newmouse = mouseclick()
if newmouse>oldmouse then menu=1
rem ** PROCESS **
if menu = 1 then gosub menu
if menu = 2 then gosub options
rem ** OUTPUT **
if game_started=1
print "This is the game, woo yay fun!... What do you mean 'Is this it?'"
else
print "You haven't started a game yet. Normally you'd go straight to the menu but I want to stall you and make you click the mouse!"
endif
sync:cls
loop
rem main menu (pause menu after player has been in the game loop)
menu:
rem make the text bigger
set text size 30
cls
rem since all these buttons function the same I will discribe just one in detail.
rem check if the player's mouse is over the button
if mousex()>120 and mousex()<520 and mousey()>120 and mousey()<180
rem make button icons that will change when the player mouses over them
box 120,120,520,180,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
rem depending on if the program has been to the game loop we will display the main menu or the pause menu
if game_started
ink rgb(255,255,255),0 : center text 320,135,"RESUME"
else
ink rgb(255,255,255),0 : center text 320,135,"START"
endif
rem if the player clicks the mouse then do something
if newmouse > oldmouse
`In the final menu: if game_started=0 then setup new game, but here we don't need to.
game_started=1 :`if it's 0 we set it to 1, if it's already 1 then it wont mind being set to 1 :D
endif
else
box 120,120,520,180,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
if game_started
ink rgb(0,0,0),0 : center text 320,135,"RESUME"
else
ink rgb(0,0,0),0 : center text 320,135,"START"
endif
endif
if mousex()>120 and mousex()<520 and mousey()>210 and mousey()<270
box 120,210,520,270,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 320,225,"OPTIONS"
if newmouse > oldmouse then menu = 2
else
box 120,210,520,270,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 320,225,"OPTIONS"
endif
if mousex()>120 and mousex()<520 and mousey()>300 and mousey()<360
box 120,300,520,360,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 320,315,"EXIT"
if newmouse > oldmouse then end
else
box 120,300,520,360,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 320,315,"EXIT"
endif
return
rem options menu
options:
rem make the text bigger
set text size 20
cls
rem I left you a button for your custom keybind control. Hope that's what you were picturing
if mousex()>200 and mousex()<440 and mousey()>100 and mousey()<160
box 200,100,440,160,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 320,120,"Change Keys"
`if newmouse > oldmouse then
else
box 200,100,440,160,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 320,120,"Change Keys"
endif
box 70,210,270,260,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 170,225,"Set Display Mode"
if mousex()>270 and mousex()<370 and mousey()>210 and mousey()<260
box 270,210,370,260,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 320,225,"640 x 480"
if newmouse > oldmouse then set display mode 640,480,32
else
box 270,210,370,260,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 320,225,"640 x 480"
endif
if mousex()>370 and mousex()<470 and mousey()>210 and mousey()<260
box 370,210,470,260,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 420,225,"800 x 600"
if newmouse > oldmouse then set display mode 800,600,32
else
box 370,210,470,260,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 420,225,"800 x 600"
endif
if mousex()>470 and mousex()<570 and mousey()>210 and mousey()<260
box 470,210,570,260,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 520,225,"960 x 720"
if newmouse > oldmouse then set display mode 960,720,32
else
box 470,210,570,260,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 520,225,"960 x 720"
endif
if mousex()>220 and mousex()<420 and mousey()>300 and mousey()<350
box 220,300,420,350,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
ink rgb(255,255,255),0 : center text 320,315,"BACK"
rem return to the menu and set text back to big!
if newmouse > oldmouse then set text size 30 : menu = 1
else
box 220,300,420,350,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
ink 0,0 : center text 320,315,"BACK"
endif
return
When you write conditional statements, you need to be sure of what is conditional and what isn't. Here's an example from your code.
rem check if the player's mouse is over the button
if mousex()>120 and mousex()<520 and mousey()>120 and mousey()<180
rem make button icons that will change when the player mouses over them
box 120,120,520,180,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
rem depending on if the program has been to the game loop we will display the main menu or the pause menu
if game_started
ink rgb(255,255,255),0 : center text 320,135,"RESUME"
else
ink rgb(255,255,255),0 : center text 320,135,"START"
endif
rem if the player clicks the mouse then do something
if newmouse > oldmouse
`In the final menu: if game_started=0 then setup new game, but here we don't need to.
game_started=1 :`if it's 0 we set it to 1, if it's already 1 then it wont mind being set to 1 :D
endif
else
box 120,120,520,180,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
if game_started
ink rgb(0,0,0),0 : center text 320,135,"RESUME"
else
ink rgb(0,0,0),0 : center text 320,135,"START"
endif
endif
Your first condition checks if the mouse is on the button; does this effect whether the button is drawn or the text printed? No, so these can be placed outside the statement. The clue is that you have put these commands on both sides of the condition.
The box command is not actually a duplicate because you have specified an ink colour as part of its parameters. We can choose to separate the ink and move the box out of the condition, or leave them as one inside the condition, whichever works best for our needs.
I think I'll leave the box as it is and as a little touch I'll make it expand when the mouse is on it.
rem RESUME/START
rem mouse over button
if mousex()>120 and mousex()<520 and mousey()>120 and mousey()<180
box 118,118,522,182,rgb(0,255,0),rgb(255,0,0),rgb(0,255,0),rgb(255,0,0)
rem set text colour (we store this in a variable because ink might be changed before we print the text).
textcol=rgb(255,255,255)
rem on click
if newmouse > oldmouse then game_started=1
else
box 120,120,520,180,rgb(55,0,0),rgb(255,0,0),rgb(55,0,0),rgb(255,0,0)
textcol=0
endif
rem button text
if game_started then btn$="RESUME" else btn$="START"
ink textcol,0
center text 320,135,btn$
Note how short my comments are. I appreciate you trying to explain your code but you want to avoid comments that are too wordy.
For big if statements it's helpful to have a comment above that tells the reader the context of the condition, e.g.
rem mouse over button
if mousex()>120 and mousex()<520 and mousey()>120 and mousey()<180
Here I've explained in very few words that the code below is executed only if the mouse is over the button. You only need to tell the reader what a true condition means, false is obviously the opposite.
To compare here is one of your comments.
rem depending on if the program has been to the game loop we will display the main menu or the pause menu
if game_started
I don't think this actually needs a comment at all. Game_started is a very good variable name and it's clear that game_started=1 means a game has been created.
A habit that you want to get out of is describing what will happen after the condition; you are just describing the condition here, if elements inside the condition need further explanation they can be commented individually. This way you don't pile information onto the reader all at once, and it makes editing easier because if you move things around you probably wont have to edit your comments at all!
Do oranges know what colour they are?