0 votes

So I have a JSON file with multiple entries and variables like this

{
"1": {
"Name": "Player1",
"Race": "Elf",
"SubRace": "Wood Elf",
"Class": "Wizard",
"Str": 10,
"Dex": 10,
"Con": 10,
"Int": 10,
"Wis": 10,
"Cha": 10
},
"2": {
"Name": "Player2",
"Race": "Dwarf",
"SubRace": "Hill Dwarf",
"Class": "Fighter",
"Str": 10,
"Dex": 10,
"Con": 10,
"Int": 10,
"Wis": 10,
"Cha": 10
}
}

Say if I want to change one variable from one entry, for example the "Race" variable of entry 2 from the JSON file and save it accordingly, so that I can assign that function to a button. How do I write it in GDScript?

in Engine by (19 points)

1 Answer

0 votes

JSON is typically not used for storing the actual application state in... but more for storing and retrieving it from a file or service.

What you would do is load it when the program starts into something your application would use while it runs, and then on exit you would save it to the JSON. While running you would just modify your in memory data structure. partly because I/O operations are slow and can impact your game flow.

I've not tested the contents of this video out, but looks like it is what you are trying to do.

https://www.youtube.com/watch?v=L9Zekkb4ZXc

To line it up with my above comment he talks about loading and saving from Godot's dictionary type.

by (50 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.