IncRelationship not working

Announcements, support questions, and discussion for the Dialogue System.
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

IncRelationship not working

Post by Sternutation »

Context- we have a C# script set up that 1)adds a dialogue actor component to a NPC and 2)assigns an initial relationship value between that actor and the player. This script was made because the NPCs in the game will be instantiated at runtime and randomly generated. For testing purposes, the NPC is set to start one specific conversation. Snippet of this C# script is given below(from the Start Method)-

Code: Select all

//ActorName = gameObject.name;
        dialogueActor = gameObject.AddComponent<DialogueActor>();
        dialogueActor.actor = ActorName;
        string luaScript = "Actor['" + ActorName + "'] = { Name = '" + ActorName + "', Display_Name = '" + gameObject.name + "'}";
        Lua.Run(luaScript);
        SetRelationship = "SetRelationship(Actor[" + @"""" + DialogueLua.StringToTableIndex(dialogueActor.actor) + @"""" + "], Actor[" + @"""Player""" + "]," + @"""NPC"""+ ", "+initialValue+")";
        Lua.Run(SetRelationship);
        GetRelationship = "return GetRelationship(Actor[" + @"""" + DialogueLua.StringToTableIndex(dialogueActor.actor) + @"""" + "], Actor[" + @"""Player""" + "]," + @"""NPC""" + ")";
        relationValue = Lua.Run(GetRelationship).AsFloat;

The issue we are running into is that using IncRelationship in this manner-IncRelationship(Actor[Variable["ConversantIndex"]], Actor["Player"], "NPC", value) does not seem to do anything in the dialogue system. It does not actually update the value. We tested it out by running GetRelationship.AsFloat in the Update() method but it remains at initialValue forever.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: IncRelationship not working

Post by Tony Li »

Hi,

Try using Lua.Run(expression, true) to log the Lua.Run() invocation to the Console window.

Temporarily add a Lua Console component to your scene. Press ~+L to open it in play mode.

It may be that Variable["ConversantIndex"] isn't what you expect it to be. In the Lua Console, check the actual actor name. For example, if your Start method had set:

Code: Select all

ActorName = "Fred";
dialogueActor.actor = ActorName;
string luaScript = "Actor['" + ActorName + "'] = { Name = '" + ActorName + "', Display_Name = '" + gameObject.name + "'}";
Then enter this in the Lua Console:

Code: Select all

return GetRelationship(Actor["Fred"], Actor["Player"], "NPC")
Check if it returns the correct value.

You can also try manually calling IncRelationship in the Lua Console:

Code: Select all

IncRelationship(Actor["Fred"], Actor["Player"], "NPC", 50)
Then check GetRelatonship again to make sure it changed. Also check the Unity Console window for any warnings or errors.
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

Re: IncRelationship not working

Post by Sternutation »

Hello Tony,

Thanks for the quick response, as usual. This Lua console component is extremely helpful.

On testing it out, it does seem that the actor is being assigned correctly(the GetRelationship with ActorName as "Fred" for both the console and the dialogue actor script is working and returning initialValue).


Evidently, the problem lies in the Lua code that uses Variable["ConversantIndex"]. This is what it looks like in the DialogueSystem script field for me-

Code: Select all

IncRelationship(Actor[Variable["ConversantIndex"]], Actor["Player"], "NPC", 5);

When I used IncRelationship with Actor["Fred"] in the Lua console it worked. But in the Lua script the above code does not work.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: IncRelationship not working

Post by Tony Li »

While the conversation is playing, open the Lua Console and try:

Code: Select all

return Variable["ConversantIndex"]
Maybe the conversation is picking up the wrong GameObject for the conversant.

BTW, you can also do much the same thing in the Dialogue Editor window. In play mode, the Templates tab becomes a Watches tab where you can set watches on variables, quests, and general Lua expressions as well as run arbitrary Lua code.
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

Re: IncRelationship not working

Post by Sternutation »

The Output when using return Variable["ConversantIndex"] in the Lua console during conversation is "NPC".

That seems to be the built-in actor name. This means that for some reason "Fred" is not being assigned as the actor to the conversation even though I have a Dialogue System Trigger that starts the Conversation on them.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: IncRelationship not working

Post by Tony Li »

Hi,

Can you assign Fred's GameObject to the Dialogue System Trigger's Actions > Start Conversation > Conversation Conversant value?
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

Re: IncRelationship not working

Post by Sternutation »

Just did so. However, the output returned is still "NPC" rather than "Fred".

I know that "Fred" gets created as an actor at runtime, as the dialogue actor component that is added at runtime has three options- "Player", "NPC" and "Fred".
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: IncRelationship not working

Post by Tony Li »

Hi,

Let's make sure the conversation is using Fred's GameObject. Please temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. When the conversation starts, look for a Console log like this:

Dialogue System: Starting conversation 'title' with actor=player and conversant=Fred.

Check if the conversant is correct. If so, double check that the Fred GameObject's Dialogue Actor > Actor field is set to "Fred".

You may also find the Character GameObject Assignments manual page to be helpful.

If that doesn't help, please feel free to send a reproduction project or reproduction steps to tony (at) pixelcrushers.com. I'd be happy to take a direct look at it.
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

Re: IncRelationship not working

Post by Sternutation »

Yes the conversant is showing up as Fred.

And the DialogueActor Actor field is showing up as Fred as well. Relationship value still remains at InitialValue though.

And when I do return Variable["ConversantIndex"] in the console I still get "NPC".
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: IncRelationship not working

Post by Tony Li »

Hi,

What about Variable["Conversant"]?
Post Reply