Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Player data files  (Read 1542 times)
0 Members and 1 Guest are viewing this topic.
Offline CogWheelz
« Posted 2014-08-05 03:32:42 »

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:
1  
2  
3  
4  
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?
Offline Ecumene
« Reply #1 - Posted 2014-08-05 03:43:59 »

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.

You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 271
Exp: 5 years



« Reply #2 - Posted 2014-08-05 03:53:12 »

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

This is backwards if anything.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ecumene
« Reply #3 - Posted 2014-08-05 03:57:44 »

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.

You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.
Offline CogWheelz
« Reply #4 - Posted 2014-08-05 04:27:05 »

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
Offline Longor1996
« Reply #5 - Posted 2014-08-05 12:06:55 »

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

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline VIrtueeL
« Reply #6 - Posted 2014-08-05 14:55:21 »

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

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline Longor1996
« Reply #7 - Posted 2014-08-05 15:09:38 »

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.

Sorry for my bad English! That's because i am from Germany.
Offline VIrtueeL
« Reply #8 - Posted 2014-08-05 15:11:20 »

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

all i can do is

getValue();
and getName();

what is this good for?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #9 - Posted 2014-08-05 15:15:00 »

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

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #10 - Posted 2014-08-05 18:11:29 »

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

Writing:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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.

Sorry for my bad English! That's because i am from Germany.
Offline CogWheelz
« Reply #11 - Posted 2014-08-05 18:27:40 »

I've never made a sandbox before, so how would you even create map data?
Offline VIrtueeL
« Reply #12 - Posted 2014-08-05 19:01:21 »

blocks and id's?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline SwordsMiner

JGO Coder


Medals: 6
Projects: 2
Exp: 1 year


The one and only.


« Reply #13 - Posted 2014-08-06 02:59:08 »

NBT is the bomb, here is what I use for Project NAH as far as saving the world:

https://github.com/Revereor/Project-NAH/blob/master/src/com/revereor/game/world/chunk/manager/ChunkFileInterface.java

and players:

https://github.com/Revereor/Project-NAH/blob/master/src/com/revereor/game/player/manager/PlayerFileInterface.java

Feel free to interpret it however and pick it apart.

If I made you laugh, helped you at all, or did something cool, I only ask that you smash that appreciate button with your nose.
Offline CogWheelz
« Reply #14 - Posted 2014-08-06 03:05:50 »


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

« JGO Bitwise Duke »


Medals: 271
Exp: 5 years



« Reply #15 - Posted 2014-08-06 03:09:13 »

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

JGO Coder


Medals: 6
Projects: 2
Exp: 1 year


The one and only.


« Reply #16 - Posted 2014-08-06 03:15:24 »

-snip-
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.

As BurntPizza said, its a serialization protocol/file format but its not encrypted, there are many NBT editors orientated towards Minecraft that uses NBT. I would use a system like this anyday (used this because I am familiar with minecraft code and I didn't want to reinvent the wheel on this level)

NBT is hierarchical, essentially its a list in lists in lists (I don't know if that's the best way to explain it?) You can save to the core compound tag things such as bools, ints, bytes, etc, and you can save other compound tags to such, You can utilize these compound tags to save arrays of things, and then access tags in those compound tags.

If someone can explain it better, in all means do.

EDIT: Found the specifications including all the nitty gritty details and the behind the scenes, contains everything you need to know: https://web.archive.org/web/20100310144708/http://www.minecraft.net/docs/NBT.txt

If I made you laugh, helped you at all, or did something cool, I only ask that you smash that appreciate button with your nose.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xFryIx (57 views)
2014-11-13 12:34:49

digdugdiggy (35 views)
2014-11-12 21:11:50

digdugdiggy (29 views)
2014-11-12 21:10:15

digdugdiggy (23 views)
2014-11-12 21:09:33

kovacsa (46 views)
2014-11-07 19:57:14

TehJavaDev (50 views)
2014-11-03 22:04:50

BurntPizza (50 views)
2014-11-03 18:54:52

moogie (65 views)
2014-11-03 06:22:04

CopyableCougar4 (63 views)
2014-11-01 23:36:41

DarkCart (149 views)
2014-11-01 14:51:03
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!