Is there a way to store Player information to a file and have AI extract the data to use and represent the player?

Player information ranges from things like keypress or x & y positions over time.

I had thought about saving the info in a 2D array and save it to a text file format but I need to know whether there is a way that an AI can use that stored information after several sessions and reference it so that it can behave just like the player did afterwards.

I am planning to create an AI to represent the player by using methods like machine learning algorithms.
I also need to know if it is possible to use algorithms for the movement like A* pathfinding combined with another algorithm that decides what actions to take based on the circumstances.

Thanks in advance.

Sure, write to a file using ‘Application.persistentDataPath’

That’s the secret

string filePath
filePath = Application.persistentDataPath+"/"+"yourFileName.txt";

To write (or overwrite) just do this

File.WriteAllText(filePath, yourText );

It is saved forever on the user’s device (unless of course they delete the app, obviously).

To read it

string allText = File.ReadAllText(filePath);

It’s that simple.

Save any text you want - you may prefer to use csv format, json, xml, whatever.

#Note, for 2016 only use Application.persistentDataPath - it’s that simple.

Be aware of …

#…OLD QA ON THIS TOPIC…

…which mentions a whole lot of nonsense about finding filepaths, etc.

Here’s a cheat sheet…

// IO crib sheet..
// check if file exists	System.IO.File.Exists(f)
// write to file File.WriteAllText(f,t)
// delete the file if needed File.Delete(f)
// read from a file File.ReadAllText(f)