Sign in to follow this  

menu logic

This topic is 2047 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)

[CODE]
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

switch(whichOne){
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";

if(nextPG){
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...";}
}
break;

public IEnumerator WaitForNext(int currentPage, string whichOne){
nextPG = false;
if (holdcount < 1){
holdcount++;
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;
}

}
}
[/CODE]

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:


[quote]
triggermenu --> makeMenu(true, "smith");

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

switch(name){
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.

break;
}
}
}


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.
[/quote]

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

This topic is 2047 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this