Player data files

I’m thinking of saving player data and possibly world data. Usually, this kind of data would end up encrypted. I think i would have to make some sort of txt file containing data like this:

892u38992842304823ur99rf nr28rm0c480m,0v,k8up,9s3uc4ta,t
sdf8uv9y9yne9yyty4738yrt874ynva7yw37ey6978y34y278y7y378r345
235iu89u29u8ru82u38ur82u8u8ewufrn02auuuuuuon2r87545y75q43545
r784wynq9ay7hmv8isw7mcy78w3a87y78ryghw8sehdgir99438rhgy973

and scan for certain data on each line. But for map data like a sandbox, how would that go?

I don’t know much about performance, or save-files. But you shouldn’t really worry about encryption. If the player want’s to edit their save file, allow them. Its their fault if the screw up. You shouldn’t spend dev-time on a feature that locks people from making level-editors and cool content-creation stuff.

As for the save file type, depends on the game :wink: If you have a world where you can place a lamp on a house, then move the house and the lamp at the same time, use XML. Theres allot of really good parsers (XML-Java) out there for it (JDOM!!!). For state based games, serialization would be your best-bet ( I think ). Its like saving java fields to a file in raw data. For example, you’d save your current level stats (like enemy and player health) into a save folder with .ser file extensions (save1/player.ser, save1/entity-entitiyID.ser).

So for editable terrain and creatable-objects, go XML.
For story-state-based, X-number of entities per pre-defined level, go serialization.

Sorry if I got serialization wrong, I’ve never used it. But I do know the concept of it.

This is backwards if anything.

Well, I meant for cascading-child systems, you’d use XML, because its laid out that way. But for saving basic data types for players, entities, and entities, you’d go for a simpler structure like serialization, because its made to save per-object stuff like that. Right? I’m still learning this stuff, It was my best guess.

Thanks, I’ll have to find some sort of example. And when i talked about the encryption, i was talking about player stats. Wouldn’t want anyone getting top stats.

I would be saving player data and data of an in game drawn tile map

I would recommend JNBT for saving things, but thats just my personal opinion.
Have a nice day.

  • Longor1996

how do i use this to save data is there any tutorials i cant find any?

Have you ever heard of something called Javadocs?
JNBT has them here:
http://jnbt.sourceforge.net/doc/

Go and read them, using the JNBT library is extremely easy.
The most important classes are NBTInputStream, NBTOutputStream, and CompoundTag.

ok i did DoubleTag db = new DoubleTag(“PlayerSpeed”,Speed);

all i can do is

getValue();
and getName();

what is this good for?

so with inputStream i can use something from a file then after its used close the file so i dont need to read it anymore?

am new to
inputStream
and
outputStream

The following may not be exactly how you should do it, but it should help.

Writing:


CompoundTag root = new CompoundTag("root");
NBTOutputStream out = null;
try
{
    out = new NBTOutputStream(new FileOutputStream(new File("player.dat"));
    out.writeTag(root);
}
catch(IOException e)
{
    e.printStackTrace();
}
finally
{
    out.close();
}

Reading:


NBTInputStream in = null;
CompoundTag root = null;
try
{
    in = new NBTInputStream(new FileInputStream(new File("player.dat"));
    root = in.readTag();
}
catch(IOException e)
{
    e.printStackTrace();
}
finally
{
    in.close();
}

CompoundTag’s getValue method gives you access to a ‘Map’, in that Map you can put all your data by putting it into other Tag’s.

I’ve never made a sandbox before, so how would you even create map data?

blocks and id’s?

Thanks, is this meant for serializing or encrypting the data?

NBT is a serialization protocol/file format. It was actually created by Notch if you find that cool.