Hello there,
I have done my best to find the answer, but my search hasn’t returned anything and I’ve been at it a while…
I am using NPC AI Engine for Unity version 3.3.0.
I have an AI character who has a narrative design setup with a few stages. These stages instruct the NPC to trigger some custom actions that I have created. This is all working and I can interact with the character in my scene as expected - all good so far…
However, I have one action that looks inside the player’s inventory and does a calculation, which stores an integer for later use and also (try to) return the value back as a response. Basically for context, I am creating a tax collector character, whom the player has to bargain with to reduce a fee they need to pay.
The problem is that the action’s return value is not visible to the NPC. I want the NPC to say something like “You owe [number] gold”. The NPC does indeed fill in a number, but it’s made up. It is not returning the value from the action…
For simplicity sake: Here’s a simple version of the code - calculatedTax is a global variable int:
public int CalculateTax()
{
calculatedTax = 50;
return calculatedTax;
}
I have this in DoAction - as mentioned, the action is working, because I use it the calculated value later in another action and I can see debug messages.
case ActionChoice.CalculateTax:
yield return CalculateTax();
break;
I have also tried returning action result to the Convai log - something like this:
if (_currentNPC != null)
{
ConvaiLogger.Info($"ACTION_RESULT: {calculatedTax}", ConvaiLogger.LogCategory.Actions);
}
I can see the action result in the log as well, but I don’t know how it is used by the NPC. Certainly it wasn’t working for me.
My narrative design basically just consists of a section that says:
Call the “CalculateTax” action.
use the value returned from the CalculateTax action to tell the user how much they owe…
Basically at the appropriate time, I would see the value 50 being calculated, so the action is being called, but my NPC would say “you owe 10 gold”, then at the given time, it would collect 50 gold from the player.
What am I doing wrong please. What else do you need to know to further diagnose?