So I prototyped a menu system for npcs, and I'm trying to figure out if I could do it better. Basically there are potentially more than 20 npcs with dialogue over several levels in the game.
Currently, when you trigger a dialogue from an npc, it calls a function makeMenu(true, npcName, interactionNum){}
Within that function is a switch for the npcName, within the npc's "case:" it has an if-else to check interactionNum and I'm wondering if a second switch would be better, within a switch?
switch(npcName){
case "smith":
if(interactionNum == 0){}
if(interactionNum == 1){}
if(interactionNum == 2){}
if(interactionNum == 3){}
break;
case "mage":
if(interactionNum == 0){}
if(interactionNum == 1){}
if(interactionNum == 2){}
if(interactionNum == 3){}
break;
//etc repeated 20x
}
Instead of:
switch(npcName){
case "smith:
switch(interactionNum){
case 1:
//dialogue 1
break;
case 2:
//dialogue 2
break;
case 3:
.//dialogue 3
break;
}
case "mage":
switch(interactionNum){
case 1:
//dialogue 1
break;
case 2:
//dialogue 2
break;
case 3:
.//dialogue 3
break;
}
//etc repeated 20x
}
On top of this there are quests in addition to dialogue, and it's on mobile.
Any advice or recommended reading? Thanks



















