IMO json is more human-readable than ini/cfg as long as you have a decent json reader. cfg/ini is still better if your users are going to be directly editing it though.
How to save things with Godot, for real
My favorite is https://jsoneditoronline.org it's pretty simple and web-based but has great features.
(Don't use an online editor if you have anything sensitive like private keys though)
Thank you for your helpful post! Something I learned today while perusing the docs to see if GDScript has a context manager like Python is that you don't need to call close() on the file, at least not in these examples.
FileAccess will automatically close when it's freed, which happens when it goes out of scope or when it gets assigned with null. In C# the reference must be disposed after we are done using it, this can be done with the using statement or calling the Dispose method directly.
I thought this was interesting! Tbh, I'll probably continue to call close() because it makes me nervous not seeing it explicitly handled.
I know this is an older thread, but THANK YOU. Figuring out Saving/Loading has been my personal nightmare, and this helps immensely!!
Hey, I've made an updated and more extended guide on forums.godotengine.org
https://forum.godotengine.org/t/how-to-load-and-save-things-with-godot-a-complete-tutorial-about-serialization/44515
at first i thought of using json but it quickly turned messy. easiest is to use godot's built in resources.
Im kinda interested how would you save 3D world state for like 100s of npc's and their positions and inventory, attack states and other params? I havent made anything that big yet but this is on my mind.
Is there a post on how to structure data in your games, for multiplayer games?
kuligs2 Im kinda interested how would you save 3D world state for like 100s of npc's and their positions and inventory, attack states and other params?
That's an interesting question. I have yet to tackle it, but I envisage experimenting with DB. Nope, I won't have attacks (almost) and the game is single player. But hundreds of characters (potentially several thousand) and different states and statuses.
Tomcat I always wondered, if you use sea-quel (SQL) DB for the game, you need to run server. How do you package SQL server with the game? Its understandable if you make GAAS type of a game, where it doesnt work if you are not connected to some service, but as a ofline SP/MP game? I know how to do it, as standalone application, using docker, pretty easy to run DB server, but im more interested how to run it inside the game itself. And maybe if its a multiplayer game, how do you share data with the other player client? Do you make entries in the other players DB or do they both connect to one server?.. etc..
- Edited
kuligs2 pretty easy to run DB server, but im more interested how to run it inside the game itself.
Maybe I don't know much yet, but why can't a game run a DB server internally?
The thing is, I'm not making a one-off game, but a project. In which I'm going to start with a simple game, and then complicate and expand it. And in the beginning there will be one character, then two, then a dozen. At that I will use resources and json. And when it gets closer to a hundred, I will start experimenting with SQL. So these are very distant plans.
Multiplayer, or rather the ability to exchange data, I assume to do, yeah, through a single dedicated server, not directly between players. But this is an optional feature, not mandatory for the game.
- Edited
kuligs2 How do you package SQL server with the game?
SQLite is a self-contained database engine. There's no separate client and server. It lets you access a database, which resides in a file, using SQL queries.
There's an SQLite Godot addon, but I haven't had a reason to use it.
https://godotengine.org/asset-library/asset?filter=sqlite&category=&godot_version=&cost=&sort=updated
A separate DB client and server are needed if the database resides on a remote server, and you want it to serve queries from a local client. Another case could be separating the client and server processing for performance reasons.
- Edited
kuligs2 I always wondered, if you use sea-quel (SQL) DB for the game, you need to run server. How do you package SQL server with the game? Its understandable if you make GAAS type of a game, where it doesnt work if you are not connected to some service, but as a ofline SP/MP game?
TL;DR: You can run a local server along side with the game executable or even in memory of the game executable itself.