Friday 13 October 2017

Need help with saving data to .json

Alright, so I'm making a discord bot RPG game, and I need to make a way for players to create their character and save their characters to an array in a .json file.I want the output into a file called players.json to look something like[ { "id":132603064220778496, //there user ID "name":"Player1", //name specified as an argument after the command //then some base stats for a new character }, { "id":132603064220778496, //there user ID "name":"Player2", //name specified as an argument after the command //then some base stats for a new character } ] I already have File Systems installed, and I'm using it to pull enemies from an enemys.json file, but I need to also be able to write new characters into the players.json.What I'm looking to do (tl;dr):Run a for loop to see if the user id is already inside of an index in the arrayIf it isn't, then find what the last index is (players.length)Then add all the info according to the command into the next available index position in the players.jsonI'm mainly having trouble with the last bit, as so far, I've only been able to overwrite all the data in the file with a fixed set of data, nothing else.tyvm in advanced!

Submitted October 13, 2017 at 07:12PM by Voxxey

No comments:

Post a Comment