Understanding the language, error messages, etc.
by qubist » Wed Aug 20, 2014 10:05 pm
Hey guys. I have a menu set up and one of the options in the menu is another menu. It looks like this:
•Settings
---Setting1
---Setting2
---SettingN
•Restart
•Foo
•Quit
Using
- Code: Select all
case -1:
break;
I can make the outer menu go back to the game when "B" is pressed, but how would I make the inner menu go back to the outer menu when "B" is pressed?
Thanks so much!
-
qubist
-
- Posts: 31
- Joined: Thu Mar 27, 2014 1:58 am
- Location: USA
by Myndale » Thu Aug 21, 2014 1:32 am
This what you're after?
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb = Gamebuino();
#define MAINMENU_LENGTH 2
const char strSubMenu1[] PROGMEM = "Submenu 1";
const char strSubMenu2[] PROGMEM = "Submenu 2";
const char* const main_menu[MAINMENU_LENGTH] PROGMEM = {
strSubMenu1,
strSubMenu2
};
#define SUBMENU1_LENGTH 2
const char strItem1a[] PROGMEM = "Item1a";
const char strItem1b[] PROGMEM = "Item1b";
const char* const sub_menu_1[SUBMENU1_LENGTH] PROGMEM = {
strItem1a,
strItem1b
};
#define SUBMENU2_LENGTH 2
const char strItem2a[] PROGMEM = "Item2a";
const char strItem2b[] PROGMEM = "Item2b";
const char* const sub_menu_2[SUBMENU2_LENGTH] PROGMEM = {
strItem2a,
strItem2b
};
void setup() {
gb.begin();
show_opening_screen();
}
void loop() {
boolean itemSelected = false;
while (!itemSelected) {
switch(gb.menu(main_menu, MAINMENU_LENGTH))
{
case 0:
itemSelected = show_sub_menu_1();
break;
case 1:
itemSelected = show_sub_menu_2();
break;
default:
break;
}
}
show_opening_screen();
}
void show_opening_screen() {
gb.titleScreen(F("Menu Test"));
}
boolean show_sub_menu_1() {
switch(gb.menu(sub_menu_1, SUBMENU1_LENGTH)) {
case 0:
gb.popup(F("You selected item 1a"), 100);
return true;
case 1:
gb.popup(F("You selected item 1b"), 100);
return true;
default:
return false; // nothing selected
}
}
boolean show_sub_menu_2() {
switch(gb.menu(sub_menu_2, SUBMENU2_LENGTH)) {
case 0:
gb.popup(F("You selected item 2a"), 100);
return true;
case 1:
gb.popup(F("You selected item 2b"), 100);
return true;
default:
return false; // nothing selected
}
}
-
Myndale
-
- Posts: 507
- Joined: Sat Mar 01, 2014 1:25 am
by qubist » Thu Aug 21, 2014 1:50 am
Is the "default" what you do if there was nothing chosen, or is it the "case -1:"
-
qubist
-
- Posts: 31
- Joined: Thu Mar 27, 2014 1:58 am
- Location: USA
by Myndale » Thu Aug 21, 2014 3:25 am
qubist wrote:Is the "default" what you do if there was nothing chosen, or is it the "case -1:"
It's what gets run if none of the other case statements handle the result...so it includes -1 in this particular case.
-
Myndale
-
- Posts: 507
- Joined: Sat Mar 01, 2014 1:25 am
by qubist » Thu Aug 21, 2014 3:41 am
OK great. I've got it working now (with help from my dad). Thanks
-
qubist
-
- Posts: 31
- Joined: Thu Mar 27, 2014 1:58 am
- Location: USA
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 67 guests