- Home /
SQLite and Lists in C#
Hello everyone,
I've been creating a game and I've recently started using database to store data and wondering how to do it online and offline.
I am using SQLite 4 Unity 3d (and sincerely don't know if it is the best way to store data in C#), and I'm able to save information as long as it is intenger, float, strings, etc.
But I recently needed to save a list of strings, or numbers, and I've been strulling a bit to understand the concept behind this (since I'm a newbie with database, XML, SQL, and anything related to saving data offline or online).
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace SQLite.models{
public class PlayerClass{
[PrimaryKey, AutoIncrement]
public int level {get; set;}
public float money {get; set;}
private List<string> tanksOwnedName {get; set;}
[SerializeField]
public string tanksOwnedNameJSON {
get {
return StringSerializationAPI.Serialize(tanksOwnedName.GetType(), tanksOwnedName);
}
set {
tanksOwnedName = (List<string>)StringSerializationAPI.Deserialize(tanksOwnedName.GetType(), value);
}
}
}
}
What you can see above is a Player class where the player will own tanks in this case.
Can someone enlighten me with databases, does and donts, with storing data online and offline.
Many Thanks in advance to all of you.
You may want to look into using a JSON string to collect your data and the database to store it. Just make sure to use a coroutine for any online server saves so it will wait long enough to perform the operation. The only problem locally is to initialize your commands before using them. Since you are using a namespace, you should be fine. I would shy away from using X$$anonymous$$L, JSON is much cleaner, faster and better all around.
Answer by GilbertoBitt · Aug 08, 2016 at 04:38 PM
for me the best way offline was creating a persistent file like txt, xml or samething like that.. and in game using scriptable objects to store all data through all scenes.. and when i use online services i send this data trough json utility. and that's it! i already like u use this sqlite but what i see on this plugins it's too complicate for simple things... i hope my answer helped you! any questions feel free to do it.