DialogueLua.SetConversationField does not work for boolean values

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ava
Posts: 17
Joined: Tue Oct 30, 2018 2:53 pm

DialogueLua.SetConversationField does not work for boolean values

Post by ava »

Hi,

If I try to do something like

Code: Select all

DialogueLua.SetConversationField(DialogueManager.Instance.lastConversationID, "IsStarted", true);
then

Code: Select all

DialogueLua.SetConversationField(DialogueManager.Instance.lastConversationID, "IsStarted").asBool;
always returns false. I believe this is because the boolean becomes a string "True" while for lua that should be "true"

I used to use an older version of the DialogueSystem for which I wrote this method myself (it didn't exist yet back then) and this one works, it is also more alike the other SetItemField and SetActorField methods.

Code: Select all

public static void SetConversationField(int conversationId, string field, object value)
{
  if (Lua.Environment.GetValue("Conversation") is not LuaTable luaTable) 
    throw new System.NullReferenceException("Conversation table not found in Lua environment.");
  if (luaTable.GetValue(conversationId) is not LuaTable elementTable)
    Debug.LogError($"Failed to find conversation {conversationId} to set field {field} to {value}.");
  else
  {
    Lua.WasInvoked = true;
    elementTable.SetNameValue(StringToTableIndex(field), LuaInterpreterExtensions.ObjectToLuaValue(value));
  }
}
Post Reply