Page 1 of 4

Save in TXT file

Posted: Tue Sep 24, 2019 3:49 am
by Mchia_Soo
Hey! It's me again!

My project is basically to collect the information from NPCs. The information will be displayed in Quest Journal.

I wish to save the information that the player has collected into .txt file.
Is there any function that I can use to save information?

Re: Save in TXT file

Posted: Tue Sep 24, 2019 9:17 am
by Tony Li
Hi,

You basically want to save the contents of the player's quest journal UI to a text file, correct?

If so, there isn't a single function to do this. However, you can still get the content with some API calls. Roughly, something like this will get the content:

Code: Select all

var questJournal = QuestMachine.GetQuestJournal();
var txt = string.Empty
foreach (var quest in questJournal.questList)
{
    txt += quest.title + " (" + quest.GetState() + ")\n";
    contents = quest.GetContentList(QuestContentCategory.Journal);
    foreach (var content in contents)
    {
        txt += content.runtimeText + "\n";
    }    
}
System.IO.File.WriteAllText("filename.txt", txt);

Re: Save in TXT file

Posted: Fri Sep 27, 2019 3:51 am
by Mchia_Soo
Hey Tony!

The code is worked. But the output displayed are repeated. How can I avoid this problem?

Re: Save in TXT file

Posted: Fri Sep 27, 2019 7:59 am
by Tony Li
It should basically be the same output that appears in the quest journal UI. The difference is that the TXT outputs all quests in the player's quest journal, including all inactive, active, and completed quests.

What repeated information do you see?

Re: Save in TXT file

Posted: Tue Oct 01, 2019 5:20 am
by Mchia_Soo
Oh, I made a mistake in my code. And yes, now the information is displayed as same as the one shown in Quest Journal.

I realise that when the quest is successful, the information is replaced by the quest state. But I want to keep the information after the quest is completed (doesn't matter it's failed or successful).

Re: Save in TXT file

Posted: Tue Oct 01, 2019 8:45 am
by Tony Li
The GetContentList method gets the content for the current quest state. If you want the same text to appear for the success and failure states, currently you need to put the same text in those states. If you use a text table, you can point them both to the same field in the text table.

Re: Save in TXT file

Posted: Tue Oct 01, 2019 10:10 am
by Mchia_Soo
The information, that I want to display in the text file, is the option player chooses in the game. So basically not all information will come out in the text file. And I'm not using text table, so yea.

Re: Save in TXT file

Posted: Tue Oct 01, 2019 10:24 am
by Tony Li
Hi,

Are you talking about options the player chooses during a Dialogue System conversation? Or some other option?

Re: Save in TXT file

Posted: Tue Oct 01, 2019 11:00 am
by Mchia_Soo
Yes, the options in the Dialogue System.

Re: Save in TXT file

Posted: Tue Oct 01, 2019 3:31 pm
by Tony Li
Hi,

Dialogue System conversations are not stored in Quest Machine, so you will need to do something different for them. You can do something like the Dialogue System's ConversationLogger.cs script. This script normally logs the conversation to the Console window / output log. But you can record it in your own place, too.