Data Issues

I have this function that is supposed to save a string however I’m getting an error saying: (23,16): error CS0136: A local or parameter named ‘dataPath’ cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter I did use this once for a pc game and it worked, the game i’m working on is a iOS game does that have anything to do with it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

public class MainMenuDataManager : MonoBehaviour
{
   
    public static MainMenuDataManager instance;

    public string currentLanguageData = "/CurrentLanguage.dat";

    private void Awake()
    {
        if (instance == null)
            instance = this;
    }

    public void SaveString(string dataPath, string stringToSave)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string dataPath = Application.persistentDataPath + stringToSave;

        FileStream stream = new FileStream(dataPath, FileMode.Create);

        MainMenuData mainMenuData = new MainMenuData();
        mainMenuData.currentLanguageData = stringToSave;

        formatter.Serialize(stream, mainMenuData);
        stream.Close();
    }

}

The error simply means you have a duplicate variable name in the same scope.

You have a dataPath parameter for your SaveString method on line 20, and a dataPath variable inside that method on line 23.

It looks like you’re not even using the dataPath method parameter, so you can just remove it.

Thanks for the reply, I had some strange stuff going on I fixed it, I haven’t worked on this in a while, thanks for the help.