- Home /
Best Storage Method
I'm making a 2D Minecraft or Terraria style game and I'm not sure on how to handle the storage portion for each block. Temporarily I have three arrays called blockType, posX and posY. If I want to read and write each of these arrays in some file what should the format be?
Thanks.
Answer by Julien-Lynge · Oct 17, 2011 at 11:47 PM
This seems like a largely philosophical question. How are you going to be accessing the data? Do you just want to write the temporary arrays into the file and then read them back out? Do you want to store indexed entries and get an entry by index? Are you saving when closing the program and reading when opening, or accessing during runtime, and are you going to have multiple threads attempting to read the file at the same time?
Perhaps you should first look at serialization (here and here) to produce binary files. Or, you could write the data out in xml format if you prefer and it's not too large.
If you can give me a little more information on what you're trying to do, I can give you some better ideas on how to go about reading and writing the data.
Yeah sure! Here we go: I guess I want to write out the arrays in a file (I'm not sure how else they'd get there). Yes I would like to store indexed entries because I think checking to see which values are closest to my player then showing those blocks with the corresponding position values would possibly be a good culling system (I don't have unit pro with the occlusion culling built in feature). $$anonymous$$aybe something like:
blocks, type, position, X, Y,
Or something I'm not sure. I will be saving when closing the program but only like the player position and what he has in his inventory nothing huge. However when the program writes the block data to a file will be when you generate a new world it's not procedural. Yes I'll access it during runtime because I need a culling system so I'll have to show and hide blocks depending on the players position at runtime. I'll just have one thread parsing the data that's really all I need nothing too complex.
About serialization, I definitely want it because I don't want people able to just open the file and edit the block types to all diamonds lol.
Just ask if you or someone else needs more information.
You could just use playerprefs? If you want to store arrays in playerprefs there is a script on the unify wiki which is located here
http://www.unifycommunity.com/wiki/index.php?title=ArrayPrefs2
Your answer
Follow this Question
Related Questions
PlayerPrefs.GetString returns wrong value 3 Answers
Can Unity use .ini files? 1 Answer
How to write/read .txt on FTP (Javascript) 3 Answers
Reading files in Unity from different platform 2 Answers
Using System.IO for Diary? 0 Answers