Page 1 of 2

Error in Corgi Inventory Example

Posted: Tue Jul 02, 2019 2:26 pm
by lostmushroom
I'm getting a few issues with the Corgi Inventory Example. When Dude1 gives you a teddy bear, the console shows the following errors.

- The referenced script (Unknown) on this Behaviour is missing
- The referenced script on this Behaviour (Game object 'Dialogue Manager') is missing
- Dialogue System: Lua code 'mmAddItem("MainInventory", "Teddy", 1)' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
UnityEngine.Debug:LogError(Object)

And the teddy bear does not show up in Inventory.

Is this just a simple missing script or is there something else going on here?

Thanks for your help :)

Re: Error in Corgi Inventory Example

Posted: Tue Jul 02, 2019 3:19 pm
by Tony Li
Hi,

That example also uses Inventory Engine, which is an inventory system included with Corgi. Did you import the Dialogue System's Inventory Engine Support package?

Re: Error in Corgi Inventory Example

Posted: Tue Jul 02, 2019 4:12 pm
by lostmushroom
Oops, no I didn't! I'll do that and see if it works.

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 2:53 pm
by lostmushroom
Imported the support package, the scene works now.

I have another question. How can I add conditions relating to the inventory to dialogue options? Let's say I want to have a dialogue option show up only if the player has 5 coins in their inventory. What's the best way to go about this?

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 3:08 pm
by Tony Li
Hi,

Use the Inventory Engine Lua Functions documented on the Inventory Engine Support page.

For example:
  • Dialogue Text: "Hey, moneybags! Can you spare some of those coins?"
  • Conditions: mmGetQuantity("MainInventory", "Coin") >= 5

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 3:12 pm
by lostmushroom
Ah nice, I almost had it. I was missing the >=5 which seems very obvious now... :D

Thanks!

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 3:23 pm
by lostmushroom
Just tried it, getting an error unfortunately.

Dialogue System: Lua code 'return mmGetQuantity(MainInventory, Coin) >=1;' threw exception 'Exception has been thrown by the target of an invocation.'

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 3:38 pm
by Tony Li
Use quotes, like this:

Code: Select all

mmGetQuantity("MainInventory", "Coin") >= 5
Also, the inventory name (e.g., "MainInventory") must exactly match the name of your inventory GameObject. In the Dialogue System's Corgi Inventory Example scene, this GameObject is named "MainInventory".

The second parameter, "Coin", must be the name of an Inventory Engine item.

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 4:35 pm
by lostmushroom
The code is working, but the quest isn't playing as I intended. Maybe I've missed something.

I have two dialogue options: "I have a coin" and "I don't have a coin".

The condition for "I have a coin" is: mmGetQuantity("MainInventory", "Coin") >=1;
The condition for "I don't have a coin" is: mmGetQuantity("MainInventory", "Coin") <=0;

However, even if you have 1 coin, the option "I have a coin" doesn't show up. The only way I can get it to show it to change the condition from >=1 to .=0, but then both options show up. Have I made a mistake somewhere?

Thanks for all your help btw, it's appreciated.

Re: Error in Corgi Inventory Example

Posted: Wed Jul 03, 2019 5:15 pm
by Tony Li
Try removing the ";" at the end.

You only need a semicolon to separate statements. Since your condition only has one statement, you don't need it.

For debugging, you can also type:

Code: Select all

return mmGetQuantity("MainInventory", "Coin")
into the "Run" bar at the bottom of the Dialogue Editor's Watches section, or in a Lua Console at runtime. You can also enter the full conditions, such as:

Code: Select all

return mmGetQuantity("MainInventory", "Coin") >=1
and:

Code: Select all

return mmGetQuantity("MainInventory", "Coin") <=0
to see what results they return.