Error in updating Quest fileds through code at runtime

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
molasses
Posts: 5
Joined: Mon Dec 27, 2021 6:58 am

Error in updating Quest fileds through code at runtime

Post by molasses »

Hi, I write a QuestManager script to manage quests, and want to synchronize the quest data between script and Dialogue Database. When the quest conversation start, I use code below to change the quest field in database:

Code: Select all

public void OnQuestAccepted(int index)
    {
        DialogueLua.SetQuestField("DOG HELP Quest", "questcode", AllQuests[index].hashcode);
        if (!string.IsNullOrEmpty(AllQuests[index].target1))
        {
            DialogueLua.SetQuestField("DOG HELP Quest", "target1", AllQuests[index].target1);
            DialogueLua.SetQuestField("DOG HELP Quest", "target1num", AllQuests[index].targetNum1);
        }
        if (!string.IsNullOrEmpty(AllQuests[index].target2))
        {
            DialogueLua.SetQuestField("DOG HELP Quest", "target2", AllQuests[index].target2);
            DialogueLua.SetQuestField("DOG HELP Quest", "target2num", AllQuests[index].targetNum2);
        }
    }
And when the quest is accepted, I use this method to change quest states in script:

Code: Select all

private void SetQuestStateInCode(double hashcode, double state)
    {
        AllQuests[(int)hashcode].questState = (int)state;
    }
However, I found that the quest field "questcode", "target1" , "target1num" did'nt change, Where is the problem?
Attachments
Quest fields
Quest fields
Snipaste_2022-01-27_20-26-10.png (96.12 KiB) Viewed 148 times
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error in updating Quest fileds through code at runtime

Post by Tony Li »

Hi,

The Dialogue Editor doesn't show runtime values (except for the Watches tab). It shows the original values in the database.

Are you sure your OnQuestAccepted() method is running?

If so, are you sure the strings are non-empty and they are calling DialogueLua.SetQuestField()?

If so, then at runtime use the Watches tab to see the values of the fields.

If you're in a build, you can add a Lua Console component and use it to print the values, such as:

Code: Select all

return Quest["DOG_HELP_Quest"].target1
Post Reply