Getting bool from other script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Dragonception
Posts: 30
Joined: Sat Jan 19, 2019 2:14 pm

Getting bool from other script

Post by Dragonception »

If I want to set as a condition the bool from a script outside the Dialogue System, how should I proceed?

I have a public bool IsItemInInventory(string searchedObject) in Inventory.cs, which uses the RPG.Core namespace.

Now I want to only display conversation option 2 if this bool returns true for IsItemInInventory("FireEssence"), i.e. I need the true value of this bool to be a condition.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting bool from other script

Post by Tony Li »

1. Register IsItemInInventory with Lua.
Example

Code: Select all

using PixelCrushers.DialogueSystem;
...
void OnEnable() {
    Lua.RegisterFunction("IsItemInInventory", this, SymbolExtensions.GetMethodInfo(() => IsItemInInventory(string.Empty)));
}

void OnDisable() {
    Lua.UnregisterFunction("IsItemInInventory");
}
2. Set conversation option 2's Conditions field to:

Code: Select all

IsItemInInventory("FireEssence") == true
Dragonception
Posts: 30
Joined: Sat Jan 19, 2019 2:14 pm

Re: Getting bool from other script

Post by Dragonception »

Fantastic! That works.
Post Reply