Question:
I need to save a player’s data in a text-based project I’m working on, but without access to any windows or webpages, I’m not sure how I can use localStorage. Is there any package, etc. that could assist with this?
//Saves data on player's turn
let plDtSave=JSON.stringify(playerData)
localStorage.setItem("SavePlayer", plDtSave)
let ptIxSave=JSON.stringify(playerData)
localStorage.setItem("SaveIndex", ptIxSave)
//Loaded at the start of the game through getItem().
Let me know if you need any additional information - I’m most likely to check this during 8AM-2PM EST.
I’m pretty sure there’s no way to write local files for individual users in raw JS. The best advice I could give is to turn your project into a website (just by making an HTML/CSS/JS replit) and showing the console output as text on the webpage. That way, localStorage should work and it also won’t be a console app anymore, so people can play it in their browsers.
Obviously, you could use a JSON file instead of a text file and then use JSON.stringify and JSON.parse to make sure everything is in the correct format.
Got it, thank you very much. I’ve come to terms with the fact that I’ll probably have to alter most of the project in some way, but this will likely allow the least required alteration of code (to my knowledge) while providing a variety of benefits. Thanks for the input, y’all!