• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Conny14156

how to go to be considered when making save/load functionality?

12 posts in this topic

Hi,

I done some googling and reading but am still unsure how I should make my save "file", I was thinking about making a text file for readability, but what should I "save" into the file so I don't end up with a thousand differently save files.

 

Me and my friend is trying to make a RPG-ish game (2D), so we got stuffs like health and inventory etc. How am I suppose to save my "inventory" into the file? for health I thougth about just saving it in plain number format but what am I suppose to do with the inventory? should I check each slots to see what item it is and save the said item into a a "Inventory" folder with seperated files as "Slot 01".txt with infomation about the item? I was thinking about just saving itemID but we decided to try to have "Randomized" items where they have a chance to have different component that grant stuffs(ex. Double jump). 

 

 

0

Share this post


Link to post
Share on other sites

You can save a json string (or something similar) into one text file, or an XML file. Those formats let you save a key and a value for everything you want to save and you can nest key-value pairs as a value of other key for things like storing array/map data. Some samples here: http://json.org/example.html

 

If you choose those formats you'll probably find also a library to read and write that kind of files, without implementing the parsers yourself.

 

If the items can have random values you can store the values in those formats and keep it readable, but you might want to encrypt the information in the future so the players can't just edit the save file to get things (which would make the "readable" requirement impossible).

 

Also, if you don't use those or other standard formats, the idea of different files for different items sounds really bad. Everything will be organized, but you'll have to add a lot more logic (references from one file to another, file creation and deletion for new or removed items, you'll have to check if an item isn't already saved in one file if you save again, etc).

Edited by DiegoSLTS
0

Share this post


Link to post
Share on other sites

Unless you really have a need to reference different files, like in Minecraft for example (where things are very dynamic), you should keep the save to one data file.

You should use a binary file, so that it is 1: Harder for most people to cheat, and 2: it is much faster to write and read a save with binary. Who needs readability for a format like this? If you want to see what it contains, write a simple Save Viewer or something. 

 

Since a computer doesn't need to look at a text saying "slot 0", "slot 1", "health", etc..., you can just skip that part.

You can have a byte which has the slot count, and then a byte or two with health.

 

Something else you should really pay attention to is versioning the formats. If you notice a big design flaw in the save format after game release, you want to let the player be able to convert their old save file to the new format. I'm sure the players would be upset if an update just deleted their save.

 

If you want to read the save file without a program, then XML and JSON are good alternatives.

Edited by diventurer
0

Share this post


Link to post
Share on other sites


Since a computer doesn't need to look at a text saying "slot 0", "slot 1", "health", etc..., you can just skip that part.
You can have a byte which has the slot count, and then a byte or two with health.
 
Something else you should really pay attention to is versioning the formats.

 

When working with binary files, you also need to pay attention to endianness.

1

Share this post


Link to post
Share on other sites

Well, there different aproaches to this kind of problem.

 

Usually a save is loaded into memory, extracting the values you want to use, by doing this you can modify those stored values, assemble the save file and write to disk.

 

if you want readabilty, you can make a readable file save using a format you desing or JSON, for example

 

JSON

inventory: {
	slot1: [itemID1, itemID2, itemID3, itemID4],
	slot2: [{potionbagID1: [potionID1, potionID2, potionID3]}, itemID2]
}

by doing so you just need to parse each value, if you want to save you write the file with updated values.

 

CUSTOM FORMAT

[Inventory]

slot1: itemID1; itemID2; itemID3; itemID4;
slot2; bagitemID; itemID2;
bagitemID: potionID1; potionID2; potionID3;

[equipment]

slot1: itemID1; itemID2;

Same as JSON, but you just have to code your own parsing rules for a format like this.

 

There's one more type of file save most comonly used because it's efficient and is file-size friendly

 

BINARY FORMAT

010203010201

By having this your program knows internally that at offset 0x00 up to offset 0x02 there will be the space for saving items in slot1, up to 3 items can be saved until you somehow tell your program that items can be allocated dynamically, from 0x02 up to 0x03 there will be the allocation space for slot2 up to 2 items can be saved, and so on.

 

I highly recommend the binary format since it's easier to parse, using custom formats will allow the player modify them with more ease, while binary formats can be encrypted or obfuscated and confuse users.

0

Share this post


Link to post
Share on other sites

If you're using a C++11 compliant compiler you can check out cereal, it's a new serialization library that supports xml, json and binary formats. I looks fairly easy to use though I haven't tried it myself, I just saw it pop up on isocpp.org.

1

Share this post


Link to post
Share on other sites

When working with binary files, you also need to pay attention to endianness.


Kinda sorta.

All PCs are x86 (little-endian), two of the three major game consoles this generation are x86 (XBone and PS4), the vast majority of mobile devices and gaming handhelds are ARM-based (bi-endian technically, but to my knowledge iOS/Android/WP/DS/Vita all run in little-endian mode), leaving only the PPC devices out there (also bi-endian, but the WiiU runs in big-endian mode). Endianness was a major concern for gameas in previous generations of game hardware (Xbox360/PS3 were big-endian PPC), but not so much for new games code being started today. Them kids seem to have it easier with every generation. smile.png

Also note that ports typically do not allow sharing of save games from other ports, and especially not between PCs and consoles. The end result is that you don't really need to care about endianness at all for things like file saves.

Deal with endianness when you're forced to and ignore it everywhere else. No reason to waste mental energy and time on a hypothetical problem you're not actually running into.
2

Share this post


Link to post
Share on other sites

Thanks for all the help guys, 
I think I will go with the binary and seeing that this is a school project(and hobby), we not thinking about porting for the moment and will just be for PC. so I want to try at this binary save "challenge". beside cereal is there any other lib I should look at?(Not that am complaining just wanted to know what options I have)

0

Share this post


Link to post
Share on other sites

Protobuf is a library to consider when dealing with serialization / creation of custom file type, I personally use it for storing levels data. You just create a proto file with your class structure like this:



message InventorySlot
{
  required int32 itemId = 1;
  required int32 itemcount = 2;
}

message CharacterData {
     required string name = 1;
     required int32 health = 2;
     repeated InventorySlot inventory = 3;
}

then you use the generator to create your c++ classes (or other language, there is a lot of decent third party protobuf library / generator available : http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns ), and you can use the built-in SerializeToOstream function to save your objects content into a binary file. 

 

Another library I used for save file in one of my RPG project is SQLite, which is a file based database library. No need to have a server or anything, just include the library in your project, and you can open a database file and use SQL command like it's a normal database. It's geared toward speed and small memory footprint.  you need to know a little about SQL, but the advantage is that you can patch your save file really easily. I also played around with integrating an economy system, built-in sql function make it easy to do so.

Edited by dlan
1

Share this post


Link to post
Share on other sites


Since a computer doesn't need to look at a text saying "slot 0", "slot 1", "health", etc..., you can just skip that part.
You can have a byte which has the slot count, and then a byte or two with health.

 

the order in which you read and write data can implicitly define whats being read/written:

 

write(player.health)

for a=0 to maxslots

   write(item[a].type)

   write(item[a].quantity)

 

 

read(player.health)

for a=0 to maxslots

     read(item[a].type)

     read(item[a].quantity)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0