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

조회 수: 1 (최근 30일)
Wesley
Wesley 2013년 3월 19일
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