Variables in text file


#1

Hey everyone.

I’m making a simple platformer game and I want to use variables for settings.
I’d like to be able to edit the variables in a text document.
Example:

[display]
height=1920
width=1080
fullscreen=1

Is this possible with the JSON stuff?
(I’m kinda new to that, so that’s why I’m asking this.)

Thanks in advance.


#2

Check this for files https://editor.gdevelop-app.com/?project=example://filesystem-create-directory
And this for parse JSON to a variable https://editor.gdevelop-app.com/?project=example://parse-json-string


#3

So, if I follow that, will it work like I said?


#4

Sure you first decide the fields you want to store in the JSON, do the events logic to save and load the JSON data to a variable(Global or Scene), then manipulate the results of the variable like any other variable in GDvevelop.
The saved file could even have any extension like gameData.save or whatever extension you want, that in case you don’t want to save as gameData.json.

Look what I do is this, check the filename is SaveThePrincess.sav but the code inside is JSON.


#5

I am actually not familliar with the formatting of this:"{" + ““Line1”:“first line”,” + ““Line2”:“second line”” + “}”
Does it have something to do with a programming language?


#6

That is JSON syntax
https://www.w3schools.com/js/js_json_syntax.asp


#7

Wow, that’s a pretty dumb question, LOL.
Thanks for your help!


#8

No problem, if you need any help just ask the community is here for help :slight_smile:


#9

Hey, one question.
I’m trying it right now.
But how do I define where and under what name the json file should be saved?
In this example you sent, I don´t see anything about a name.

EDIT: When I export the game, I don’t see a json file either.


#10

When you use Filesystem the JSON file is saved in the user PC, in order to do that you need to set the directory that you want to use for saving the file I do like this. For set up the directory


And this when i collect some item then update the file

And this for load the saved file into a variable


Filesystem syntax
#11

Thanks for all the work.
Here you save a variable into a JSON file, in the example you sent, you used parse JSON string.
What is the difference?

Oh yeah and why do you have SaveThePrincess.sav? what does the .sav mean?


#12

.sav is the extension that i use for saved file, intead of use .json, it’s a way to basically hide that really is a json file. you can use any extension you want