Page 1 of 1

Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Wed Jan 29, 2020 2:56 am
by ko_games
I have a weird issue going on where the quest alert won't show any text if I use a trigger event. I have a basic cube with a trigger box collider, a trigger event script, and a quest control script. If I choose QuestControl.ShowAlert the background of my alert shows, but not the actual text typed in the Trigger event. However, if I use an alert through the quest editor>>Node>>Action>>Alert Text the alert will show up just fine with the text. I'm sure I'm missing something obvious, but I'm not sure what it is.

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Wed Jan 29, 2020 8:28 am
by Tony Li
Hi,

Are there any errors or warnings in the Console window?

Immediately after triggering the alert, please pause the game so the alert doesn't disappear when its time is up. Then inspect the Quest Alert UI. Does it contain an entry for the alert text?

questAlertUI.png
questAlertUI.png (50.24 KiB) Viewed 1445 times

If not, we'll need to figure out why.

If it does, then perhaps the text is somehow too big to fit into its RectTransform, or is otherwise present but not visible.

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Thu Jan 30, 2020 1:19 am
by ko_games
I paused the game during the two alerts. The one that works when triggered through the Quest node and the one that doesn't when triggered with the Trigger Event Script.

Screen Shot 1--This is the one that doesn't work. Triggered with Triggered Event Script.


Screen Shot 2--This is the one that does work. Triggered with Quest node.


From what I can see it looks like in the case of the Trigger Event Script (Screen Shot 1) for some reason no Container Template(Clone) is created with the text as a child of that clone. The Quest node alert (Screen Shot 2) does work and seems to be creating the Container Template(Clone).

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Thu Jan 30, 2020 8:34 am
by Tony Li
Hi,

Here's a patch:

QM_AlertUIPatch_2020-01-30.unitypackage

Tick the new "Always Use Container Template" checkbox on the quest alert UI.

The original behavior is an optimization. When Quest Control only shows an alert string, it only instantiates a copy of the body text template and adds it directly to the container.

If you tick "Always Use Container Template", it will instantiate the full container template just like the quest node action does.

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Fri Jan 31, 2020 3:09 am
by ko_games
Hi Tony,

The patch did work to get the text to display, but I'm not getting the result I expected. Maybe I'm going about this the wrong way. My goal is to show an alert each time a player completes a task. For example, I'm using a counter to keep track of how many bathrooms have been flooded. So each time the player floods a bathroom I wanted to display an alert like this screen shot (see screenshot 1 bellow). I can make the alert show up like this in quest nodes by adding a heading text and a body text. The problem I'm having is I don't know how to make it show an alert like this each time the counter increases. There is only inactive, active, true, and conditions states. So my thought process was to use the trigger even script to display an alert each time the player completed a task. The text shows now, but it doesn't have the same formating (see screen shot 2). What would be the best way to accomplish this goal?

Screenshot 1


Screenshot 2

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Fri Jan 31, 2020 9:10 am
by Tony Li
Hi,

The catch is that the Trigger Event isn't tied to a quest, so it doesn't know which quest to grab the value of {#floodedBathrooms} from.

If you don't mind a little scripting, you can use the QuestMachineTags.ReplaceTags method, something like:

Code: Select all

using PixelCrushers.QuestMachine;
...
Quest quest = QuestMachine.GetQuestInstance("Flood Bathrooms"); //<--(your quest ID here)
string original = "Flooded {#floodedBathrooms} / {>#floodedBathrooms} Bathrooms";
string forDisplay = QuestMachineTags.ReplaceTags(original, quest);
QuestMachine.defaultQuestAlertUI.ShowAlert(forDisplay);
Otherwise (if you don't want to do any scripting) you can show the alert from inside the quest. However, to do this you'll need to add three condition nodes, such as Flood Bathroom 1, Flood Bathroom 2, and Flood Bathroom 3. In the True > Actions section of each node, add Alert Text with "Flooded 1/3 Bathrooms", etc.

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Sat Feb 01, 2020 5:48 am
by ko_games
Thanks Tony! That worked.

If I wanted to create a custom script that gets the minimum, maximum, and current value of a specific counter on a quest how would I do that? My goal would be to have a script that can reference those values and check to see when they have been updated. That way when the counter is updated or has reached its max I can perform certain actions through scripting.

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Sat Feb 01, 2020 7:58 am
by Tony Li
Hi,

First get the quest, for example using QuestMachine.GetQuestInstance("quest ID").

Then use Quest.GetCounter("counter name"). This returns a QuestCounter. You can check its currentValue, minValue, and maxValue properties.

You can also register with the message system to receive messages when the quest counter value has changed. Here's an example of that:

Code: Select all

using PixelCrushers; // For message system.
using PixelCrushers.QuestMachine;

public class MyClass : MonoBehaviour, IMessageHandler
{
    void OnEnable()
    {
        // Register for counter changed messages. If you pass null as the quest ID, it listens for all quests.
        MessageSystem.AddListener(this, QuestMachineMessages.QuestCounterChangedMessage, "quest ID");
        // Should also remove listener in OnDisable.
    }
    
    void OnMessage(MessageArgs args)
    {
        counter = QuestMachine.GetQuestInstance(args.parameter).GetCounter(args.stringValue);
        int currentValue = counter.currentValue; // (can also read counter.minValue and .maxValue)
    }
}

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Sun Feb 02, 2020 5:12 am
by ko_games
That worked perfect! Thanks Tony. You are awesome!

Re: Quest Alert Doesn't Show Text When Using Trigger Event

Posted: Sun Feb 02, 2020 10:54 am
by Tony Li
Glad to help! :-)