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

1 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2013-3-19
编辑:Image Analyst 2013-3-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by