Page 1 of 1

Dialogue condition issue

Posted: Wed Feb 28, 2018 10:10 am
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:

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 10:40 am
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.

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 11:08 am
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'

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 11:18 am
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"?

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 11:29 am
by Filippo
it returns "nil"

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 11:39 am
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.

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 11:44 am
by Filippo
Thanks, now it works! :)

Re: Dialogue condition issue

Posted: Wed Feb 28, 2018 1:13 pm
by Tony Li
Great! Thanks for letting me know.