Jump to content
  • Advertisement
Sign in to follow this  

menu logic

This topic is 2357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ugh I've been going in circles with this and am wondering if there's some better way I don't know about.

Basically I have an NPC Menu system, there are half a dozen 2d textures and some 2d text elements. I lay everything out where I want it, then in my start function disable everything so they're not in view.

When the player enters a trigger surrounding an NPC, a function makeMenu() is called and passed 2 values, (bool alive, string whichNPC)

public void mainMenu(bool makeMenu, string whichOne){
if(makeMenu == true){
menu_bg.enabled = true; //background texture
menu_overview.enabled = true; //overview button
menu_quest.enabled = true; //quest button
menu_accept.enabled = true; //accept button
menu_close.enabled = true; //close button
bodymain.enabled = true; //main body text placeholder

case "smith":
next.enabled = true; //enable the "read more" button
if(interactionNum == 0){
if(pageNum ==0){
currentPage = 0;
waiting = true;
bodymain.text = "this is the text for page 1 of the first dialogue for this NPC";

StartCoroutine (WaitForNext(currentPage,whichOne)) ;}
else if(pageNum == 1){bodymain.text ="page 2 dialogue...";}
else if(pageNum == 2){bodymain.text ="page 3 dialogue...";}
else if(pageNum == 3){bodymain.text ="page 4 dialogue...";}
else if(pageNum == 5){bodymain.text ="page 5 dialogue...";}

public IEnumerator WaitForNext(int currentPage, string whichOne){
nextPG = false;
if (holdcount < 1){
while (waiting){
yield return new WaitForSeconds(0.5f);

mainMenu (true, whichOne); //refresh the menu so it can catch any changes triggered by input
Debug.Log ("refreshing Menu");
holdcount = 0;


Then in my input manager script, when the player touches the "read more" button, it sets nextPG=true, and it increments the pageNum (mainMen.pageNum++;)

So it partly works, but the problem is, when you enter a dialogue with the NPC, if you press the "read more" button, it doesn't update the menu until you break the dialogue and re-enter the trigger, which will load the incremented "pageNum" variable.

Since the dialogue is deep in a switch, I've been having troubles figuring out how to update it in real time to "step" through the dialogue windows based on the user input.

My hacky way is to pass the currentPage and NPC's name of the current window to the coroutine, then in the coroutine it "refreshes" the dialogue menu by calling it again and passing in the current page and name of the NPC. Basically it checks ever 0.5 seconds, updating the menu twice per second, if the user touches the "read more" it increments the page number variable which should then be "caught" by the makeMenu function when it checks conditions and loads the incremented pageNum text.

So pseudo code:

triggermenu --> makeMenu(true, "smith");

mainMenu(bool makeIt, string name) {
if (makeIt) {
-->enable all the GUI elements that will be used

case "smith":
-what number conversation is this:
-if first conversation, load the first page of dialogue
bodyText.text ="long string of dialogue";
enable "read more" button
startcoroutine to "pump/refresh" the menu 2x per second to catch any new conditions from user Input.


coroutine--> public IEnumerator WaitForNext(int currentPage, string whichOne)

This coroutine is passed the currentPage from the dialogue case: and the name of the NPC we were dealing with, which it passes back at the end of the coroutine in a call to makeMenu(true, whichOne)

Basically at any time the player can press the "read more" button, it might be 2 seconds after seeing the window or they might read it for 30 seconds, but it won't directly do anything other than change the values of a couple variables, that will hopefully be "picked up" by the conditional statements the next time the menu is triggered.

So as it is now, it partly works, but it doesn't update the window while the menu is drawn, you have to break the dialogue by pressing close, then re enter the NPC's trigger area and it will draw the menu based off the variables set. If the player doesn't press "read more" it will show the first page no matter how many times the break the dialogue and re-enter. If they press "read more" 3x, the next time they load the dialogue it will be on page 4.

Any advice on cleaning this up? I'm using Unity if that matters any. Edited by lmbarns

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!