Quantcast
Channel: Questions in topic: "javascript"
Viewing all articles
Browse latest Browse all 68

UnityScript for unique simpleJSON lists

$
0
0
What is the simplest way to save multiple lists of different variables in simpleJSON? Im just getting started with learning JSON and this is what I've figured out so far var Pets : List.; function SavePets(){ var PetNames = new JSONObject(); var Petnames = new JSONArray(); var PetSpec = new JSONObject(); var Petspec = new JSONArray(); var PetLv = new JSONObject(); var Petlv = new JSONArray(); for(i =0; i < Pets.Count; i++){ Petnames.Add(Pets[i].GetComponent.().Name); PetNames.Add(Petnames); Petspec.Add(Pets[i].GetComponent.().Species); PetSpec.Add(Petspec); Petlv.Add(Pets[i].GetComponent.().Lv); PetLv.Add(Petlv); } var path : String = Application.persistentDataPath + "PlayerSave.json"; File.WriteAllText(path, PetNames.ToString()); File.WriteAllText(path, PetSpec.ToString()); File.WriteAllText(path, PetLv.ToString()); } This works, but I know there has to be a less tedious way of coding this. The game I'm making is similar to pokemon. The player will have tons of 'pets' each with their own stats. The method I'm posting creates 3 different lists containing each property of an individual pet object of what I want to save. I figure I could just iterate through each of the lists on load to grab a prefab of a pet the player has raised and repopulated the stats for it.

What I would like to do is instead of having a single list for each property I want to save, to make unique arrays for each pet with their own information

so instead of lists like (rex, garfield, gumi, bojack) (dog, cat, birb, horse) (10, 12, 4, 20) to make lists like (rex, dog, 10) (garfield, cat, 12) (gumi, birb, 4) (bojack, horse, 20)

The way I wrote it is the closest way I came to accomplish saving a list of random characters the player can collect.

this code is a VERY generic example. Each 'pet' in the game can have up to 30 different stats. Im only using simpleJSON to get away from using PlayerPrefs

Here is the JSON Im using https://github.com/Bunny83/SimpleJSON/blob/master/SimpleJSON.cs

thanks for any help

Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>