Dialogue condition issue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Filippo
Posts: 4
Joined: Wed Feb 28, 2018 9:44 am

Dialogue condition issue

Post by Filippo »

Hi, I'm trying to pass a variable to the dialogue system from my script and using it as a condition in a dialogue but my script is not working and there are no errors in the console. Here's my script.

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem{
public class EntropyLuaIntegration : MonoBehaviour{
	void OnEnable() {
//		Lua.RegisterFunction("HaveStoryItem", this, typeof(bool).GetMethod("HaveStoryItem"));
//		Lua.RegisterFunction("IsChapter", this, typeof(bool).GetMethod("IsChapter"));
		Lua.RegisterFunction("StringInShortcuts", this, typeof(bool).GetMethod("StringInShortcuts"));
	}

	void OnDisable() {
//		Lua.UnregisterFunction("IsChapter");
//		Lua.UnregisterFunction("HaveStoryItem");
		Lua.UnregisterFunction("StringInShortcuts");
	}

//	public bool HaveStoryItem(string name) {
//		if(SavingManager.Manager.SST.StoryItem.Contains(name)){
//			return true;
//		}
//		else {
//			return false;
//		}
//	}
//
//	public bool IsChapter(double Chapter) {
//		if(SavingManager.Manager.SST.Chapter == Chapter){
//			return true;
//		}
//		else {
//			return false;
//		}
//	}

	public bool StringInShortcuts(string name) {
		return SavingManager.Manager.SST.Shortcuts.Contains(name);
	}

	}
}
(I've added this script to the dialogue manager in my scene)
and this is a screenshot of the condition in dialogue window:
Attachments
DS.jpg
DS.jpg (176.03 KiB) Viewed 680 times
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue condition issue

Post by Tony Li »

Hi,

Here are some suggestions to debug this.

Add a Lua Console to your scene, and press ~+L to open it. Then enter:

Code: Select all

return StringInShortcuts("FirstJaneConv")
Make sure it returns false (or true if that's what you expect at the current game state).

If you're in the Unity editor, then instead of the Lua Console you can use the Dialogue Editor window's Watches tab if you prefer. At runtime, the Templates tab turns into Watches.

Temporarily set the Dialogue Manager's Debug Level to Info. When the Dialogue System evaluates this condition, it will log one of the messages similar to below:

Dialogue System: Add Link #:3 (Jane): '...'

or

Dialogue System: Block On False Link #:3 (Jane): '...' Condition: StringInShortcuts("FirstJaneConv") == false

You can read more on conditions here: More On Conditions. In particular, be aware that the Dialogue System must evaluate conditions one extra level ahead. This is required to handle certain continue button modes.

If none of that helps, please feel free to send a reproduction project to tony (at) pixelcrushers.com. I'll be happy to take a look.
Filippo
Posts: 4
Joined: Wed Feb 28, 2018 9:44 am

Re: Dialogue condition issue

Post by Filippo »

I get this message
Dialogue System: Passthrough on False Link (Jane): ID=16:3 'Oh, ciao. In teoria dovrei difendere questo posto..ma non mi pagano abbastanza per affrontarti. Non sei male in combattimento.
' Condition='StringInShortcuts("FirstJaneConv") == false'
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue condition issue

Post by Tony Li »

Would you please add a Lua Console and enter:

Code: Select all

return StringInShortcuts("FirstJaneConv")
Does it return "false", "true", or another value such as "nil"?
Filippo
Posts: 4
Joined: Wed Feb 28, 2018 9:44 am

Re: Dialogue condition issue

Post by Filippo »

it returns "nil"
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue condition issue

Post by Tony Li »

Sorry I missed this earlier. Try changing this line:

Code: Select all

Lua.RegisterFunction("StringInShortcuts", this, typeof(bool).GetMethod("StringInShortcuts"));
to this:

Code: Select all

Lua.RegisterFunction("StringInShortcuts", this, typeof(EntropyLuaIntegration).GetMethod("StringInShortcuts"));
You want to get the method StringInShortcuts that belongs to the type EntropyLuaIntegration. The type 'bool' doesn't have a method named StringInShortcuts.
Filippo
Posts: 4
Joined: Wed Feb 28, 2018 9:44 am

Re: Dialogue condition issue

Post by Filippo »

Thanks, now it works! :)
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue condition issue

Post by Tony Li »

Great! Thanks for letting me know.
Post Reply