Save in TXT file

Announcements, support questions, and discussion for Quest Machine.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Save in TXT file

Post 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?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post 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);
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Hey Tony!

The code is worked. But the output displayed are repeated. How can I avoid this problem?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post 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?
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post 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).
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post 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.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post 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.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Hi,

Are you talking about options the player chooses during a Dialogue System conversation? Or some other option?
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Yes, the options in the Dialogue System.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post 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.
Post Reply