Save in TXT file

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

Re: Save in TXT file

Post by Mchia_Soo »

And thanks for the information. Now that I know there are 2 save systems we can use. :)
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Mchia_Soo wrote: Sat Feb 15, 2020 9:16 am
Tony Li wrote: Sat Feb 15, 2020 8:26 am Call the QuestJournal's RecordData() method. This will return a string that contains the recorded data in JSON format.
Calling this method in JsonDataSerializer script?
Yes. I'm assuming that your Save System has a JsonDataSerializer. QuestJournal.RecordData() creates a serializable object. Then it uses the DataSerializer on the Save System to serialize it. If the Save System has a JsonDataSerializer, it will serialize the object to JSON.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Tony Li wrote: Fri Feb 14, 2020 8:27 am Tick the Quest Journal's Save Settings, and untick the others (such as Quest Givers, etc.). The save system will only save what you have specified to save.
Back to this topic, which save system you are referring to?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Hi,

I'm referring to the Save System component. When you tell it to record savegame data, it tells all of the Savers in the scene to record their data. Then it stores all of the Savers' data in a dictionary (a SavedGameData object).
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

But there's no checkbox for Quest Journal's Save Settings. Where can I find those checkboxes?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

In the Quest Journal component's Save Settings foldout:

questJournalSaveSettings.png
questJournalSaveSettings.png (16.98 KiB) Viewed 1111 times
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Still don't have any idea to solve it.

Just realize that you did mention before about ConversationLogger.cs. I have modified the script to save the conversation in txt file.
But I got this error while the game is playing.

UnauthorizedAccessException: Access to the path "C:\saved.txt" is denied.
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <f826c2584fc94ec19a48a6576640bdc5>:0)

And my script is like this (I only edited the script in OnConversationLine method):

Code: Select all

        public void OnConversationLine(Subtitle subtitle)
        {
            if (subtitle == null | subtitle.formattedText == null | string.IsNullOrEmpty(subtitle.formattedText.text)) return;
            string speakerName = (subtitle.speakerInfo != null && subtitle.speakerInfo.transform != null) ? subtitle.speakerInfo.transform.name : "(null speaker)";
            string data = string.Format("<color={0}>{1}: {2}</color>", new object[] { GetActorColor(subtitle), speakerName, subtitle.formattedText.text });
            Debug.Log(data);
            System.IO.File.WriteAllText("/saved.txt", data);
        }
Am I editing at the right place?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Hi,

I'm still not sure what you ultimately want to do. But if you want to save a transcript of a conversation, you can do something similar to ConversationLogger. You don't have to customize the ConversationLogger script itself. If you import an update to the Dialogue System, it could overwrite your customizations. Try adding a script like this to your Dialogue Manager:

ConversationTranscript.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ConversationTranscript : MonoBehaviour
{
    private string transcript;
    
    void OnConversationStart(Transform actor)
    {
        transcript = DialogueManager.lastConversationStarted + ":";
    }
    
    void OnConversationLine(Subtitle subtitle)
    {
        transcript += "\n" + subtitle.formattedText.text;
    }
    
    void OnConversationEnd(Transform actor)
    {
        var filename = Application.persistentDataPath + "/transcript.txt");
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            filename = filename.Replace("/", "\\"); // Windows uses backslash.
#endif
         System.IO.File.WriteAllText(filename, transcript);
    }
}
This will save a transcript of the conversation to a file in the application's persistent data path.
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Tony Li wrote: Mon Feb 17, 2020 8:21 am This will save a transcript of the conversation to a file in the application's persistent data path.
I have added this script to the Dialogue Manager, but I couldn't find the transcript txt file in the path of the link given.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Try adding this line:

Code: Select all

   void OnConversationEnd(Transform actor)
    {
        var filename = Application.persistentDataPath + "/transcript.txt");
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        filename = filename.Replace("/", "\\"); // Windows uses backslash.
#endif
        Debug.Log("Saving: " + filename); //<-- ADD THIS LINE.
        System.IO.File.WriteAllText(filename, transcript);
    }
(I had a typo in the script that I just fixed. It had "#else" but it should be "#endif".)

After you add that line and try again, it will log the filename to the Console.
Post Reply