Skip to content
OpenHogwarts edited this page Jun 8, 2016 · 1 revision

To access game's data you can make sql like queries:

Service.db.Select<Task>("FROM tasks");

Service.db.Delete("tasks", id);

Service.getOne<Task>("FROM tasks WHERE id == ? & status == ?", id, status);

We use classes to make updates/inserts. Their public attributes will be saved on db.

Examples:

https://github.com/OpenHogwarts/hogwarts/blob/master/Assets/Scripts/Player/CharacterData.cs https://github.com/OpenHogwarts/hogwarts/blob/master/Assets/Scripts/NPC/NPCData.cs

All available tables are listed in Service.cs.

Create a new table

  1. In Service.cs.

Add an EnsureTable:

server.GetConfig ().EnsureTable<CLASS_CONTAINING_TABLE_ATTRS> ("TABLE_NAME", "ATTR_INDEX");

You can add more indexes with EnsureIndex:

server.GetConfig ().EnsureIndex<CLASS_CONTAINING_TABLE_ATTRS> ("TABLE_NAME", isUnique, "ATTR_INDEX_2");

The second attribute (isUnique) must be a var, that's why isUnique & isNotUnique vars are set.

Adding new entries

All game data is stored in a db file at runtime. Once you added a new item/quest, etc.. you will have to delete the db to regenerate it:

  1. Open Service.cs and after if (_db == null) { add the following line:

    Debug.Log(Application.persistentDataPath);

  2. Run the game to copy the printed path, close Unity (or you will get access denied as file is in use) and delete the file.

The file will be rebuild once you start the game again.

Clone this wiki locally