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 »

OH YES!!!! That's exactly what I want! This is actually like a simulation game for education where the player needs to collect the requirements from the NPCs. And what I want to save into txt file is the requirements collected by the player.

Anyways, thanks a lot Tony!!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

Glad to help! :-)
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

Hey Tony! Sorry for asking too many questions regarding this.

I just found out that this function is actually the same as Quest Journal, where it will replace the string when the quest state has changed.

Can I save the string value when the quest state is Active only? How should I fix it?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

I still don't understand. Can you provide some mock-up screenshots to illustrate what you want to do?
Mchia_Soo
Posts: 72
Joined: Sun Jun 30, 2019 11:59 pm

Re: Save in TXT file

Post by Mchia_Soo »

I'm using the same code you gave and apply it on 3 levels, but it can only save the latest level that has played.

Each level has 1 quest giver (Total 3 of them). I wanna save every quest giver's last conversation in all levels. How can I do it?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save in TXT file

Post by Tony Li »

You could try this to save each conversation in a separate file:

Code: Select all

   void OnConversationEnd(Transform actor)
    {
        var filename = Application.persistentDataPath + "/" + DialogueManager.lastConversationStarted + ".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);
    }
Or this to save each conversation according to its scene name:

Code: Select all

using UnityEngine.SceneManagement;
...
   void OnConversationEnd(Transform actor)
    {
        var filename = Application.persistentDataPath + "/" + SceneManager.GetActiveScene().name + ".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);
    }
Post Reply