- Home /
How can I store game data outside of scripts.(e.g Total list of inventory items)
I've been poking around for the answer for this question, but I keep getting questions and answers that are close in wording, but not exactly what I'm looking for.
My current project is a game with RPG elements, and my current problem right now is items.
The player's current inventory seems like a pretty straight forward concept: Use a list/associative array to create a list of items actively in the player's inventory, with their associated values set to the number of items of that name. Pretty straight forward.
But what about the overall item list/table?
My item class will look something like this:
psuedocode:
Public Class Item
{
int ID //The item's relative ID in the game.
string Name // Item's displayed name.
boolean equip // Can item be equiped?
boolean use // Can item be used?
enum location //None, Body, Hands, Feet, Accessory
int modAttribute //A few of these, for each of the game's attributes.
//Other variables, such as item# limit, game icons, etc, including all
//of the "Gets/Sets" for these properties.
}
Naturally, I could create a huge array(of this item class) to contain all of the game's inventory data in code, but it seems like it would be a pain to work with both in adding/removing/editing items, and with assigning items to certain enemies/chests/etc in order to be dropped/otherwise handled.
I've worked with databases before, but only non-local/web databases(MySql and the like.) They seem like they would be a good solution, if only they were local and/or light weight enough to use with a game. I've stored data as CSVs before, but it seems like a horrible idea to publish a game where the game's data is stored in plain/mostly plain text, and editing a CSV formated inventory list still feels.. sub-optimal.
Is there an easy way to store this kind of data outside of scripts, without a web database, and preferably in a format that couldn't easily be edited by a curious gamer in notepad?
Answer by murkantilism · Mar 18, 2013 at 04:03 PM
If you really want to deter your players from editing the inventory data, you could use an XML database, they are relatively easy to use. Then you can simply encrypt the XML text.
Take a look at this page to learn about XML encryption in Unity.
Super. I can work with this. Seems like it would be easy to save relevant game-state variables in this format as well.
Thanks for the example.
Do you know how intensive this is for processing? It mentions it towards the bottom of the blog post, and I have a hard time gauging exactly what he means by moderate sized X$$anonymous$$L file.
I thinking around 100~ items, which could be anywhere from 500-1000 lines of X$$anonymous$$L.
No problem, I'm not sure how processor intensive that method is, you may want to search for less resource heavy methods.
I$$anonymous$$O, 1000 lines of X$$anonymous$$L qualifies as a "moderate" sized X$$anonymous$$L file.
Answer by nsxdavid · Mar 18, 2013 at 03:58 PM
The basic answer for how to keep someone from editing your data files "easily" is to encrypt the file. Roll your own or use the built-in capabilities.
If you want a light-weight embeded database that is appropriate for a game, there are multiple assets for integrating SQLite databases to your game. For example.
Your answer
Follow this Question
Related Questions
Setting generic list length 2 Answers
Can't Assign Item In Array 1 Answer
Convert Inventory from JS to C# (problem with list) 2 Answers
A node in a childnode? 1 Answer