|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 03 Jul 2013 02:48 PM |
| So I guess I'll go with the text document approach with fancy weird syntax :P |
|
|
| Report Abuse |
|
|