I have a unity game where I want to store data of about 200-500 puzzles.
For the individual puzzles i am storing a lot of data like position, rotation, list of all the objects needed, list of possible answers, and few more attributes.
So my questions are
1) Can access individual puzzle data (for example 201), from the set of large json data file?
2) Is this the right methodology to follow with that amount of data?
Asked
Active
Viewed 143 times
1

randomjoe2
- 21
- 1
- 4
-
You need a database – Bender Bending Jul 17 '17 at 15:06
-
FYI, there's a [game development stack exchange site](http://gamedev.stackexchange.com) where you may get better answers. – ashes999 Jul 17 '17 at 16:39
-
Use multiple JSON files. The first one tells you what puzzles are available and where to find them, then you have 1 additional file *for each puzzle* that contains that specific puzzle's data. BAM. Problem solved. – Draco18s no longer trusts SE Jul 17 '17 at 17:29
2 Answers
0
Probably, you'll need a database to improve the searching perfomance. But, if you, for some reason can't and/or don't want to use a database, you can think about split the content in other .json files (divide by "worlds" or "themes", for example). Or, you can use FileStream to read until you find the puzzle you need.
Check if this question can help you: How can I read/stream a file without loading the entire file into memory?

Bruno Pinheiro
- 155
- 1
- 8
0
You did not specify the structure of your JSON, but if you use associative keys then finding the right single object is both fast and trivial
var gameData = {
puzzle101: {
position:"101_PositionData",
location:"101_LocationData",
otherData:[
]
},
puzzle102: {
position:"102_PositionData",
location:"102_LocationData",
otherData:[
]
}
}
var puzzle101Data = gameData["puzzle101"];
console.log(puzzle101Data)

Jamiec
- 133,658
- 13
- 134
- 193
-
So i can search the json data file for a certain key and parse that individual block of data that the key is associating to? If yes, can you please direct me with any links on how i can accomplish this? Thank you. – randomjoe2 Jul 17 '17 at 15:49
-
@randomjoe2 im sorry i dont understand - I thought you were defining the data you're storing. Just store it however you like with an appropriate key to be able to look it up. – Jamiec Jul 17 '17 at 15:50
-
yes i am defining the data, but now after you pointing this out. I will be defining the data with the key (assume 200 th). and when i try to retrieve the data. I will want to search for the key 200 and i can retrieve that object. Is that correct? – randomjoe2 Jul 17 '17 at 15:59
-
@randomjoe2 yes you can have a numeric key, if that is the question you're asking me I still dont understand – Jamiec Jul 17 '17 at 16:03