Page 1 of 1

DialogueLua.SetConversationField does not work for boolean values

Posted: Thu Sep 12, 2024 11:55 am
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));
  }
}