Page 3 of 4

Re: Save in TXT file

Posted: Sat Feb 15, 2020 9:17 am
by Mchia_Soo
And thanks for the information. Now that I know there are 2 save systems we can use. :)

Re: Save in TXT file

Posted: Sat Feb 15, 2020 10:18 am
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.

Re: Save in TXT file

Posted: Sat Feb 15, 2020 11:07 am
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?

Re: Save in TXT file

Posted: Sat Feb 15, 2020 11:31 am
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).

Re: Save in TXT file

Posted: Sat Feb 15, 2020 11:36 am
by Mchia_Soo
But there's no checkbox for Quest Journal's Save Settings. Where can I find those checkboxes?

Re: Save in TXT file

Posted: Sat Feb 15, 2020 11:43 am
by Tony Li
In the Quest Journal component's Save Settings foldout:

questJournalSaveSettings.png
questJournalSaveSettings.png (16.98 KiB) Viewed 1109 times

Re: Save in TXT file

Posted: Sun Feb 16, 2020 9:51 pm
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?

Re: Save in TXT file

Posted: Mon Feb 17, 2020 8:21 am
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.

Re: Save in TXT file

Posted: Mon Feb 17, 2020 9:34 am
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.

Re: Save in TXT file

Posted: Mon Feb 17, 2020 9:46 am
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.