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

1 Ansicht (letzte 30 Tage)
Wesley
Wesley am 19 Mär. 2013
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 19 Mär. 2013
Bearbeitet: Image Analyst am 19 Mär. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by