LoginLogin

Please help me with title screen.

Root / Programming Questions / [.]

Retrogamer123Created:
I am working on a title screen that has the options of new game, load game, and exit, butI cannot make it so that I can use a specific option, how would I do this?

do you have any sample code that you can show us of what you have done already? and tell us what kind of commands you know how to use, like gosub and such.

'Title screen

LOCATE 1,3:PRINT "New game";
LOCATE 1,4:PRINT "Load game";
LOCATE 1,5:PRINT "Exit";

SEL%=0

WHILE 1
 IF (BUTTON(2) AND #UP  ) && SEL%>0 THEN:LOCATE 0,SEL%+3:PRINT " ";:SEL%=SEL%-1
 IF (BUTTON(2) AND #DOWN) && SEL%<2 THEN:LOCATE 0,SEL%+3:PRINT " ";:SEL%=SEL%+1
 IF (BUTTON(2) AND #A  ) THEN:BREAK
 LOCATE 0,SEL%+3:PRINT ">";
 VSYNC
WEND

ON SEL% GOTO @NEW,@LOAD,@EXIT
Edit: okay fine Alright, so the first 3 lines show the options of the title screen ("new game", "load game", and "exit") The next line sets SEL% to 0, making sure the cursor is hovering over "new game" The next line starts an infinite WHILE loop, which is less messy than using a label These next two IF statements are where it becomes complex. The first one handles moving up. It checks to see if you press up on the d-pad and if so, it moves on. It then checks if the cursor is not on "new game" to make sure the cursor won't go past "new game." If that's true, it moves the cursor up by removing the cursor from the screen and subtracting one from SEL%. The second line does the same thing, but for moving down. The next line redraws the cursor at the new place. VSYNC makes sure your program runs at 60FPS if it can. WEND ends the WHILE loop.

stuff
at least explain some of it. that level of complexity could be intimidating to someone barely starting out.

This is my code:
LOCATE 20,17
PRINT "New Game
LOCATE 20,20
PRINT "Load Game
LOCATE 20,23
PRINT "Exit
A=17
S=1
@menu
B=BUTTON(2)
LOCATE 18,A:PRINT"->
IF B AND 1 THEN LOCATE 18,A:PRINT"  "S=S-1:A=A-3: BEEP
IF B AND 2 THEN LOCATE 18,A:PRINT"  "S=S+1:A=A+3:BEEP
IF S<1 THEN S=43: A=23
IF S>4 THEN S=1: A=17
VSYNC 1
Goto @MENU
What I cannot figure out how to do, is make a certain thing happen when you select each option.

your going to need to add some stuff to happen when the user presses a certain button for selection, such as A. you could use TheV360's advice by using the on command, which could be pretty useful for what youre doing.

This is my code:
LOCATE 20,17
PRINT "New Game
LOCATE 20,20
PRINT "Load Game
LOCATE 20,23
PRINT "Exit
A=17
S=1
@menu
B=BUTTON(2)
LOCATE 18,A:PRINT"->
IF B AND 1 THEN LOCATE 18,A:PRINT"  "S=S-1:A=A-3: BEEP
IF B AND 2 THEN LOCATE 18,A:PRINT"  "S=S+1:A=A+3:BEEP
IF S<1 THEN S=43: A=23
IF S>4 THEN S=1: A=17
VSYNC 1
Goto @MENU
What I cannot figure out how to do, is make a certain thing happen when you select each option.
You need to use GOTO and labels. I see you already used some in your code at line 8. (@MENU) Try this (My edited version of your program posted above):
ACLS:Y=17 'Clear the screen:Put cursor next to the "New Game" option.
@MAINMENU
 CLS 'Clear the screen of text, computer!
 LOCATE 0,0:PRINT "The cursor is this high:";Y;" " 'Print the height of the cursor.
 LOCATE 18,Y:PRINT "->" 'Print the cursor.
 LOCATE 20,17:PRINT "New Game" 'Print the "New Game" option.
 LOCATE 20,20:PRINT "Load Game" 'Print the "Load Game" option.
 LOCATE 20,23:PRINT "Exit" 'Print the "Exit" option.
 IF BUTTON(2)==1 THEN 'If the up button is pressed, then...
  DEC Y,3 'Make the cursor go up.
  IF Y!=14 THEN BEEP 12 'Make a sound if the cursor moves.
 ENDIF 'The end of what happens when up is pressed.
 IF BUTTON(2)==2 THEN 'If the down button is pressed then...
  INC Y,3 'Make the cursor go down.
  IF Y!=26 THEN BEEP 12 'Make a sound if the cursor moves.
 ENDIF 'The end of what happens when down is pressed.
 IF BUTTON(2)==16 THEN 'If the A button is pressed, then...
  IF Y==17 THEN GOTO @NEWGAME
  IF Y==20 THEN GOTO @LOADGAME
  IF Y==23 THEN END
 ENDIF 'The end of what happens when A is pressed.
 IF Y<17 THEN Y=17 'If the cursor gets too high then put it back.
 IF Y>23 THEN Y=23 'If the cursor gets too low then put it back.
 VSYNC 1 'Wait for SmileBASIC to finish drawing the text, so all the text does not blink.
GOTO @MAINMENU 'Repeat everything!
@NEWGAME
 'What you want to happen when "New Game" is selected and A is pressed.
@LOADGAME
 'What you want to happen when "Load Game" is selected and A is pressed.
You don't need to use anything after 's because it is just to tell/remind you of what that line of code does. But you can use it though because in SmileBASIC everything after 's are ignored so you can keep notes in your code. :) Also BTW I was making the comments in the code super simple if you did not understand it, if you want be to be less simple then you can ask me to post another program with less simple comments. [poll=p3][/poll]

I know a bit about how to program from petit computer, and I just have not made a menu with more than 2 options before.

I know a bit about how to program from petit computer, and I just have not made a menu with more than 2 options before.
Did I help you?

Yes