Page 1 of 2

Object does not match target type

Posted: Fri Jun 26, 2015 12:38 am
by njg
Hi,

my code started throwing the following exception

Dialogue System: Lua code 'return speakConversation(sidson,sidson,smokeweed)' threw exception 'Object does not match target type.'

It doesn't matter whether the parameters are quoted or not (question: do they have to be quoted? this may be a silly question but in other areas they don't have to be.)

The speakConversation c# function was working just fine and then it stopped working and started doing the above and I have no idea why. I have another function which is doing the same thing. If it makes a difference I changed a conversation name after it was written, I don't know if this is a no no or not, I sure hope not, I would hate to have to rebuild everything now.

Help!

Nick

Re: Object does not match target type

Posted: Fri Jun 26, 2015 9:38 am
by Tony Li
Hi Nick,

Don't worry -- you never have to rebuild any Dialogue System data! That said, some people (the belt-and-suspenders types) still like to make text-based backup copies. You can do this by exporting the dialogue database as a Chat Mapper XML file. (Just FYI. I rarely do this myself.)

In Lua, like in other programming languages, strings need to be quoted. So if your C# method is defined like this:

Code: Select all

public bool speakConversation(string actorName, string conversantName, string conversationTitle) {... 
then your Lua should look this like:

Code: Select all

return speakConversation("sidson", "sidson", "smokeweed") 
The error "Object does not match target type" can mean one of two things:

1. In Lua, you're passing the wrong type of value. For example:

Code: Select all

return speakConversation("sidson", 3.14, "smokeweed")
2. Or in C# you're registering the function (see Lua.RegisterFunction) with types that are different from the actual function definition.

Please feel free to post your C# code here or email an example project to tony (at) pixelcrushers.com. I'll be happy to take a look.

Re: Object does not match target type

Posted: Fri Jun 26, 2015 12:16 pm
by njg
here is the full stack trace:

Dialogue System: Lua code 'return speakConversation("charles anderson","when darkness falls","first")' threw exception 'Object does not match target type.'
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:IsTrue(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinksAtPriority(ConditionPriority, DialogueEntry, List`1, List`1, List`1)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinks(DialogueEntry, List`1, List`1, List`1)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry)
PixelCrushers.DialogueSystem.ConversationModel:.ctor(DialogueDatabase, String, Transform, Transform, Boolean, IsDialogueEntryValidDelegate)
PixelCrushers.DialogueSystem.DialogueSystemController:StartConversation(String, Transform, Transform)
PixelCrushers.DialogueSystem.DialogueManager:StartConversation(String, Transform, Transform)
PixelCrushers.DialogueSystem.ConversationStarter:StartConversation(Transform)
PixelCrushers.DialogueSystem.ConversationStarter:TryStartConversation(Transform)
PixelCrushers.DialogueSystem.ConversationTrigger:OnUse(Transform)
UnityEngine.GameObject:BroadcastMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.Selector:Update() (at Assets/Dialogue System/Scripts/Supplemental/Utility/Selector.cs:243)

(Filename: Assets/Dialogue System/Scripts/Supplemental/Utility/Selector.cs Line: 243)



The c# definitions and code:

Lua.RegisterFunction("advanceConversation",this,typeof(LuaConversationCharlesAnderson).GetMethod("advanceConversation"));

public bool advanceConversation(string npc,string conversation,string stage,string nextstage)
{
SQL.Update("update conversations set stage= '" + nextstage + "' where npc = '" + npc + "' and " +
"conversation = '" + conversation + "' and " +
"stage = '" + stage + "'");
return true;
}

Like I said before, it was working perfectly well and then it stopped suddenly, something I did made it stop working and I have no idea what, I didn't touch this part of the code at all as I had no reason to, I was adding new conversations and when I went to test them everything stopped working.

Nick

Re: Object does not match target type

Posted: Fri Jun 26, 2015 12:33 pm
by Tony Li
Your function has 4 parameters, but you're only calling it with 3. Is your Lua code missing something after "first"?

Re: Object does not match target type

Posted: Fri Jun 26, 2015 12:55 pm
by njg
I posted the wrong function before, (lack of sleep/migraine), but its much the same, and i did what you suggested. the odd thing is the debug statement never comes out in the editor.log file. Very weird.

public bool speakConversation(string npc,string conversation,string stage)
{
/*
string query = "select npc,conversation,stage from conversations where npc = '" + npc + "' and " +
"conversation = '" + conversation + "' and " +
"stage = '" + stage + "'";

string [,] conv = SQL.SelectRaw (query);
if(conv.GetLength(0) > 0)
{
return true;
}
else
{
return false;
}*/

Debug.Log ("~lua in speak conversation");
return true;
}

Nick

Re: Object does not match target type

Posted: Fri Jun 26, 2015 1:11 pm
by Tony Li
I'm going to be out of the office for a few hours. As soon as I get back in, I'll test out the code you posted and reply back here.

In the meantime, what versions of Unity and the Dialogue System are you using? You can find the Dialogue System's version in Assets/DialogueSystem/_README.txt.

Are you using the default Lua implementation that comes with the Dialogue System, or did you import the special NLua package?

Re: Object does not match target type

Posted: Fri Jun 26, 2015 2:08 pm
by njg
Hi

I am using the default Lua version.

Unity 4.6.5f1

------------------------------
Dialogue System for Unity
Version 1.4.5

Copyright © Pixel Crushers
------------------------------

Thanks,

Nick

Re: Object does not match target type

Posted: Fri Jun 26, 2015 2:29 pm
by Tony Li
Thanks for sending the version info. If you're game for it, you could try updating to the latest release (1.5.2). As always when importing updates for any plugin, back up your project first.

As soon as I get back to the office and check it out, I'll let you know what I find with your code.

Re: Object does not match target type

Posted: Fri Jun 26, 2015 11:40 pm
by Tony Li
Nick,

I entered the code you posted in a Unity 4.6.5 test project with the Dialogue System 1.4.5, and it works. You can download the test scene here:

njg_test_2015-06-26.unitypackage

It doesn't include the Dialogue System folder. It only includes a scene and script in Assets/njg_test.

Would it be possible for you to send an example project to tony (at) pixelcrushers.com?

Re: Object does not match target type

Posted: Sat Jun 27, 2015 2:31 pm
by njg
It used to work just fine, then something happened...given that I have your debug switch set on "error" and "Selector: line 243" is executing just fine in my onconversationstart function but failing in the speakConversation call, I don't believe the stack trace anymore, which is truly a sad thing. Somewhere in the documentation I believe it says Nlua is available only for those running Unity Pro, is this true, or has this changed and the docs not kept up, The reason I ask is I also believe in a previous conversation you had said NLua had better diagnostics, which at this point is what I am looking for. I don't think I can send you a stripped down scene that is going to prove anything one way or another, if I strip it, I suspect it will start working again. I did the upgrade, no change.

Nick