How do I make a locked conversation choice that you can see but can't choose?

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by Tony Li »

AoF wrote: Sun Jul 07, 2019 9:04 pm By the way, I *think* line 55 has a bug in it. It shows this: var luaResult = Lua.Run("return Dialog[" + response.destinationEntry.id + "].Show_Invalid");

Shouldn't that "Show_Invalid" be using the variable instead? If I understand this correctly, you couldn't evaluate at runtime if you changed the name of your variable.
Yup! Change it to:

Code: Select all

var luaResult = Lua.Run("return Dialog[" + response.destinationEntry.id + "]. " + DialogueLua.StringToTableIndex(showInvalidFieldName));

You can set the "Show Invalid" field in Lua like this:

Code: Select all

Lua.Run("Conversation[" + conversation.id + "].Dialog[" + entry.id + "].Show_Invalid = false");
But, as you mentioned, dialogue entry fields aren't included in saved games unless you assign a function to PersistentDataManger.GetCustomSaveData to save those fields.

You could add an OnConversationResponseMenu method to a script on the Dialogue Manager to check if the player has enough energy. If not, mark the response as invalid:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
 {
     foreach (var response in responses)
     {
         var energyCost = Field.LookupInt(response.destinationEntry.fields, "energyCost");
         if (energyCost > currentPlayerEnergy) // (example)
         {
             response.enabled = false;
         }
     }
 }
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by AoF »

Tony Li wrote: Sun Jul 07, 2019 9:08 pm You could add an OnConversationResponseMenu method to a script on the Dialogue Manager to check if the player has enough energy. If not, mark the response as invalid:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
 {
     foreach (var response in responses)
     {
         var energyCost = Field.LookupInt(response.destinationEntry.fields, "energyCost");
         if (energyCost > currentPlayerEnergy) // (example)
         {
             response.enabled = false;
         }
     }
 }
I may not understand, but it doesn't seem like this solves my issues.

Whether the node is shown should depend on whether you've started the quest. Whether the node is interactive should depend on whether you have enough energy. Does this provide a way of doing this? From what I can tell, this code would show the node when it shouldn't be shown (but it will be interactive in the right circumstances).
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by Tony Li »

To prepare a response menu, the Dialogue System does this:

1. Evaluates the Conditions on all nodes linked from the current subtitle. This will omit nodes whose Conditions are false -- such as if the quest hasn't been started yet. The output is a Response[] array.

2. Calls any custom OnConversationResponseMenu(Response[]) methods you've added the Dialogue Manager. You can modify the values of the Response[] array. For example, check the energyCost and set enabled=false if the player doesn't have enough energy.

3. Shows the response menu. Responses whose enabled field is true are clickable. If the enabled field is false, it's not clickable.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by AoF »

Oh! I thought enabled meant visible, not interactable. OK, that makes sense. I guess that means I don't need your code you gave me at the beginning, because I could just change the enabled field already.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by Tony Li »

That's correct.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by AoF »

Great, thank you! How do I wrap it in an em tag? I tried to do this, but it printed it literally:

Code: Select all

using PixelCrushers.DialogueSystem;
using UnityEngine;

public class ShowEnergyCostInResponseMenu : MonoBehaviour
{
    private static UnityEngine.Events.UnityAction subtractEnergyCall = () => TotalEnergy.SubtractEnergy();

    public void OnConversationResponseMenu(Response[] responses)
    {
        foreach (var response in responses)
        {
            var cost = Field.LookupInt(response.destinationEntry.fields, "energyCost");

            if (cost > 0)
            {
                response.formattedText.text = TextSprites.energy + response.formattedText.text;
                response.destinationEntry.onExecute.RemoveListener(subtractEnergyCall);
                response.destinationEntry.onExecute.AddListener(subtractEnergyCall);
                if (TotalEnergy.totalEnergy <= 0)
                {
                    response.enabled = false;
                    response.formattedText.text = $"[em1]{response.formattedText.text}[/em1]";              //this doesn't work      
                }
            }
        }
    }
}
I think I'm supposed to set response.formattedText.emphases instead, but I'm not sure where to get em1.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by Tony Li »

FormattedText contains a version of the text in which the [em] codes have already been parsed out. Try this:

Code: Select all

response.formattedText = FormattedText.Parse($"[em1]{response.formattedText.text}[/em1]");
This will re-parse the new [em] tags.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: How do I make a locked conversation choice that you can see but can't choose?

Post by AoF »

Great, thanks!
Post Reply