Game
TwoDoors


5 years ago

[v0.4.2] (https://gamejolt.com/games/TwoDoors-Game/511189)

-New Save-System

-Version/Update hint

Sorry for the long wait, I had some problems getting the Save-System up and running.

-----------------------------------

▼---Save System Code---▼


Code meant for Unity, but could work the same for normal C# as no essential code is Unity specific, just the "Debug.Log" and "Application.persistentDataPath".

The read function returns an Array of strings.

The write function needs an Array of strings to write to the text-file.

PS: The Update/Version Check uses Unitys Remote Config (https://www.youtube.com/watch?v=14njHI4CGgA&t=156s).

		
			//Read .txt File
private string[] getDataFromFile(string fileName = "SaveManager")
{
    string line;

    //Pass the file path and file name to the StreamReader constructor
    Debug.Log("Path: " + Application.persistentDataPath + "/" + fileName + ".txt");
    checkTextFileExists();
    StreamReader file = new StreamReader(Application.persistentDataPath + "/" + fileName + ".txt");
    if(!File.Exists(Application.persistentDataPath + "/" + fileName + ".txt"))
    {
        Debug.LogError("File doesn't exist.");
        return null;
    }
    else
    {
        //instatiates the temporary List list
        List<string> list = new List<string>();

        try
        {
            //Read the first line of text
            line = file.ReadLine();
            //Continue to read until you reach end of file
            while (line != null)
            {
                //add the new line to the List
                list.Add(line);

                //Read the next line
                line = file.ReadLine();
            }
            //close the file
            file.Close();
        }
        catch (Exception e)
        {
            Debug.LogError("Exception: " + e.Message);
        }

        //unloads the file
        file.Close();

        //turns the List list into an Array and returns it
        return list.ToArray();
    }
}

//You can turn a string into an int with int/float.Parse(string)
//You could also use Convert.ToInt()/.ToFloat()

//Write to .txt File
private void writeToFile(string[] data, string fileName = "SaveManager")
{
    string path = Application.persistentDataPath + "/" + fileName + ".txt";

    if (File.Exists(path))
    {
        File.Delete(path); // deletes the file, if it already exists
    }

    // Create a file to write to.
    using (StreamWriter sw = File.CreateText(path))
    {
        for (int i = 0; i < data.Length; i++)
        {
            sw.WriteLine(data[i]);
        }
        sw.Close();
    }
}
		
	


0 comments

Loading...

Next up

My entry for the GMTK Game-Jam 2020 is now online:

https://gamejolt.com/games/ricochetrampage/515711

I will now continue development on TwoDoors, v0.4.0 should be live within the coming week.

[v0.4.1]

-Dynamic loading/unloading of level (see gif)

-reworked the last two sections, added in v0.4.0

-added new model for the small crate

-improved audio-mixing

-crates now break when walking through doors

[v0.2] This update, was mainly focused on quality of life changes, f. e. that crates now interrupt lasers when held.

Some confusing parts have been reworked, as well as the progression/pacing of the puzzles.

Plus some new models and bugg-fixes.

The Cryptmaster Anniversary Update is here! 

@akuparagames saw that players loved the in-universe card minigame "Whatever." So for this update, they've put more effort to make it its own Roguelike game mode!

Try the FREE DEMO: https://bit.ly/CryptmasterSteam

[v0.4.0]

-There now are retractable Spikes/Blocks (crates on moving blocks are still buggy, trigger the blocks to move then put the crate on it)

-3 new Level !!!

-Buttons now have a "click" sound

-Jump now has a sound

After 7 long years, the wait is finally over. Chapters 1-4 of DELTARUNE are out now!

Celebrate the parallel story to Undertale by completing these quests.

[v0.3.1]

-Vases now break when dropped from greater heights : )

-UI now has scroll functionality.

-The player can finally now jump.

-----------------------------------

▼---Impact Detection Code---▼

[v0.1.1] New Game I made during Weekend-Jam#02 https://itch.io/jam/weekend-jam-2

Tower-Defense/Puzzle Game

Updates coming soon : )

The Button Effect – @Frycandle 's minimalist first-person puzzler inspired by The Witness, The Talos Principle and The Beginner's Guide, is coming to Steam! 

Play the demo and wishlist the game now: https://bit.ly/thebuttoneffect

[v0.3] Web / Linux / Mac support has been added. As stated in the 'Readme.txt' file, I currently do not have acces to Linux or Mac OS and therefore it is difficult to check for buggs.

I will try to set up a harddrive with Linux for testing in the future.