using randomValue

Announcements, support questions, and discussion for the Dialogue System.
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

using randomValue

Post by gwishinofficial »

Hi!

I can only get randomValue = math.random(4) to work if it's in the script of the Start node (followed by an empty node, then followed by set of barks). Is it possible to add it to a later node in the conversation and if yes, do I need to do something differently in order to make it work?

I ask because I'm trying to trigger some barks based on which character the player is AND which ability they just used. So I want to branch off into some groups first to use conditions.

While I'm here, I want to ask if there's a better way to handle the following situation using randomValue. I don't want there to ALWAYS be a bark when an ability is used because some abilities come up too often and it would be silly for the character to say something each time. Right now I'm putting an empy node (like say the fourth node has no dialogue) and I figured I might add a chance for that node to be greater if I want to make it more likely that the character won't say anything. Is this okay or do you foresee trouble down the line? It seems to work fine but in other similar instances I've had an empty dialogue box show up by itself.

Thanks!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: using randomValue

Post by Tony Li »

Hi,

The empty node is required because Conversations Evaluate Conditions One Extra Level Ahead. For conversations, you can tick the Dialogue Manager's Other Settings > Reevaluate Links After Subtitle to remove this restriction.

If you only want to bark sometimes, it would be most efficient to check before trying to bark. For example, if you're using a Dialogue System Trigger with Actions > Bark, then to bark only 25% of the time you could set Conditions > Lua Condition to:

Code: Select all

math.random(100) < 25
If you're barking in C# code:

Code: Select all

if (Random.value < 0.25f) DialogueManager.Bark(...);
This way the Dialogue System doesn't need to go through the steps of setting up a ConversationModel object to evaluate the conversation.

However, if it's easier to handle it in the bark conversation itself, you can "roll a d100" like below:
randomBarks.png
randomBarks.png (35.99 KiB) Viewed 153 times
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

Re: using randomValue

Post by gwishinofficial »

Thank you! That's all very helpful.

Is there a reason why my lines shouldn't work if either of these scripts started on a later node that was not the START node?

randomValue = math.random(4)
x = math.random(4)

My problem is that when I try setting them up like the flipping coins example in the link you sent me, it doesn't work. They will only work if I put one of the above scripts into the START node (even if I leave an empty node after it).
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

Re: using randomValue

Post by gwishinofficial »

To elaborate slightly, it gets stuck on the first node with the script and just sits there without moving on to the empty node after it. The only console error I get is about event loading which happens normally when I test scenes outside the build of the game and hasn't been a problem otherwise. (If this is related, I've left the Don't Destroy on Load in the Dialogue Manager ticked for the theoretical reason of wanting the build to work properly altogether but maybe that's wrong.)

Dialogue System: The scene is missing an EventSystem. Adding one.
UnityEngine.Debug:LogWarning (object)
PixelCrushers.UIUtility:RequireEventSystem (string) (at Assets/Plugins/Pixel Crushers/Common/Scripts/UI/UIUtility.cs:20)
PixelCrushers.DialogueSystem.UITools:RequireEventSystem () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Utility/UITools.cs:37)
PixelCrushers.DialogueSystem.StandardUIQuestLogWindow:Awake () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Quest/StandardUIQuestLogWindow.cs:117)
UnityEngine.Object:Instantiate<UnityEngine.GameObject> (UnityEngine.GameObject)
PixelCrushers.InstantiatePrefabs:OnEnable () (at Assets/Plugins/Pixel Crushers/Common/Scripts/Misc/InstantiatePrefabs.cs:37)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: using randomValue

Post by Tony Li »

Hi,

You can ignore that warning.

The Conversations Evaluate Conditions One Extra Level Ahead example should work as shown in the screenshot.

I think you'll need to temporarily set the Dialogue Manager's Other Settings > Debug Level to Info, reproduce the issue, and then examine the Console window. With Debug Level set to Info, the Dialogue System will show what's going on under the hood, including running Script fields and evaluating Conditions.
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

Re: using randomValue

Post by gwishinofficial »

Okay, I appreciate you walking me through this.

I turned on Debug Level to Info and looked at Console again. Comparing the two (one that works if script is on START and the one that doesn't work if the script is on the node after START), they diverge at Sequencer.Play where the working example says "None()" and the not-working example says "Delay(2)."

(I promise both examples have a node with "None()" in the Sequence field following the node with the script.)
onStart_g.png
onStart_g.png (287.65 KiB) Viewed 146 times
afterStart_ng.png
afterStart_ng.png (306.44 KiB) Viewed 146 times
Do you know why the second one would say Delay (is that the issue)?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: using randomValue

Post by Tony Li »

What is the Sequence field's value in the CombatBarks conversation's dialogue entry ID 45? I'm guessing that it's blank, so it's using the Dialogue Manager's Default Sequence of Delay({{end}}), which uses the Dialogue Manager's Subtitle Settings > Min Subtitle Seconds = 2.
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

Re: using randomValue

Post by gwishinofficial »

ID 45's sequence field has "None()":
ID45_SequenceField.png
ID45_SequenceField.png (125.4 KiB) Viewed 124 times
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: using randomValue

Post by Tony Li »

Is it possible that the Dialogue Manager's Initial Database is pointing to a different copy of that dialogue database?

As a test, set entry 45's Sequence to something like:

Code: Select all

AudioWait(Sergeant_Graves_2_3)
(Assuming you haven't deleted the Dialogue System's Demo folder.)

Does it play the audio clip?

Feel free to send a reproduction project to tony (at) pixelcrushers.com
gwishinofficial
Posts: 14
Joined: Wed Apr 24, 2024 10:13 pm

Re: using randomValue

Post by gwishinofficial »

It does not play the audio clip (afaict it stops on the node before it). I emailed you a link to the reproduction project in case you can take a look, thanks Tony!
Post Reply