How do i return to a menu box that i just came from?

1 view (last 30 days)
I am attempting to create a choose you own adventure scenario, but i do not know how to return to the previous menu box. This is what i have so far:
input=menu('Please pick what kind of characture you want to be.',...
'Hunter','Warrior','Mage','Demon','Elf');
switch input
case 1
hunter=menu('The Hunter is a characture that prefers to fight from a distance. Do you want the Hunter?','Yes','No');
switch hunter
case 1
disp('Congrates you have choosen the Hunter. Your jurney is about to begin.')
case 2
end
case 2
disp('The Warrior is a characture with a high strength.')
case 3
disp('The Mage is a Characture that attacks with magic from a distance.')
end
I would like the second case 2 to return me back to the first menu. any help would be appreciated.

Accepted Answer

Image Analyst
Image Analyst on 19 Mar 2013
Edited: Image Analyst on 19 Mar 2013
Wrap the whole thing in a while, and add break statements. Don't add a break if you want the code to repeat and ask the user again. That's one way anyway:
while true
input=menu('Please pick what kind of character you want to be.',...
'Hunter','Warrior','Mage','Demon','Elf');
switch input
case 1
hunter=menu('The Hunter is a character that prefers to fight from a distance. Do you want the Hunter?','Yes','No');
switch hunter
case 1
disp('Congratulation you have chosen the Hunter. Your journey is about to begin.')
break;
case 2
end
case 2
disp('The Warrior is a character with a high strength.')
break;
case 3
disp('The Mage is a Character that attacks with magic from a distance.')
break;
end
end
I also fixed misspellings of character, journey, congratulations, etc.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!