generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Preferred method of saving Data (Ja...

Previous Thread :: Next Thread 
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
02 Jul 2013 08:08 PM
I already have a fancy class to store and save the data, but idk if I should serialize a bunch of the classes, or just use a text file and some colons and semicolons to divide up the numbers. Any advice Scripters?
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
02 Jul 2013 08:45 PM
You could just do that, it does work. I've done it myself to save data per instance of class to load later. (the colon/semicolon thing)
This was for some Rogue-like game I stopped working on where the maps were saved raw. I had to split the files up into multiple and store them inside a compressed file to actually get it to handle loading all the data, since the maps were quite big.

Secondly, there's also XML,JSON, etc. you could also save it to - but it'd just require more code to read/write to those formats.

Last thing I can think of at this time is Regular expressions, which if you know how to use can be very useful to make your own data save format you can read and write to.
Report Abuse
TheCapacitor is not online. TheCapacitor
Joined: 19 Jan 2011
Total Posts: 7045
02 Jul 2013 08:53 PM
A haxxy method which should save everything in 12 bytes (C because I don't know java):

float a = 13.37; // 4 bytes
float b = 90.01; // 4 bytes
long c = 12; // 4 bytes
int length = sizeof(a) + sizeof(b) + sizeof(c);
char* write = (char*)malloc(length);
memcpy(&write[0], a, sizeof(a));
memcpy(&write[sizeof(a)], b, sizeof(b));
memcpy(&write[sizeof(a) + sizeof(b)], c, sizeof(c));
FILE* file = fopen("something.bin", "wb");
fwrite(write , 1, length, file);
fclose(File);
free(write);
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
02 Jul 2013 09:05 PM
I'm no expert in C++, so please don't hurt me if this bugs you 'professionals'.

@thecapacitor
My attempts at doing what you've done in C++

float a = 13.37,b = 90.01,c = 12;
std::fstream file;
file.open("D:/something.bin",std::ios::binary | std::ios::out);
std::string write = "";
std::stringstream out;
out << a << b << c;
write = out.str();
file << write;
file.close();
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
02 Jul 2013 09:07 PM
Now that I look at it, it would've saved as plain text and not binary.

Oh well.
Report Abuse
TheCapacitor is not online. TheCapacitor
Joined: 19 Jan 2011
Total Posts: 7045
02 Jul 2013 09:20 PM
C code can be embedded in C++ - IDK why you changed my code. Anyway don't save as plain text - that takes up more room. For example:

This number - 214|74836|47 - the highest 32 bit int - can be saved in 4 bytes, but if you save it as a string, its 10 bytes (11 if you wanna add a null terminator)
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
02 Jul 2013 09:21 PM
@thecapacitor

I know you can, I just wanted an excuse to paste some random code. :P

I know, it saves with more memory rendering it useless. I did realize that after I posted.
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
03 Jul 2013 02:48 PM
So I guess I'll go with the text document approach with fancy weird syntax :P
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image