JSON file not showing in editor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ZacB

I would like to add a .json file in my project to store data.
The problem is that I can’t add such files from the editor. And if I put it directly in the project’s folder I can’t see it in my editor…

Having the same problem, it seems that the language (or engine) simply can not handle json correctly. Which is really annoying. =/

Leonardo Da Vinci | 2019-02-12 02:43

:bust_in_silhouette: Reply From: BE-Never Games

This is intended, Godot’s Filesystem dock only shows built-in resources (the resource base class and all classes inheriting from it). JSON files are not built-in resources since they don’t really need to be imported. You can still open them from code thought if you create them in your project’s folder normally and get the data contained in them. Godot provides two helper classes as well as a couple of built-in GDScript functions. The ‘Saving Games’ tutorial is also worth checking out as it teaches using JSON to save game data.

thx for your answer but the problem is that I can’t have access to this json file (i put it in the project folder)… When I parse the file and ask for a certain value it just shows an error message saying that this value does not exist

ZacB | 2018-07-07 15:13

Could you quickly paste the code you’re using so that I can see if I am able to find a mistake?

BE-Never Games | 2018-07-07 15:21

i checked the tutorial you send to me and I think it’s better to incorporate the dictionnary into a script. So I’ve something like :



extends Node

const ANIMALS = {
1:{
"class":1,
"name":"dog",
"rarity":2
},
2:{
"class":2,
"name":"cat",
"rarity":1
}

(...)

}

Is it a clean way of doing this ?

ZacB | 2018-07-07 16:46

It is possible to do this, yes. However I personally would generally use it for smaller databases or data that directly originates from your gameplay code (such as save data).
It mostly comes down to personal preference, I myself am not a big fan of having huge dictionaries as a database, I usually use either JSON or a custom file format.
There is not really one distinct way to do this, storing data often depends on use case and personal preference. If this works for you then use it. I’d recommend to maybe research a bit about different ways to store data in games.

(This example with animals in particular kind of screams ‘Classes’ for me though xD)

BE-Never Games | 2018-07-07 17:08

ok thx ^^. But is there a way to use something else than a class ?

ZacB | 2018-07-07 17:36

Sorry, I was busy and then forgot to answer. There is generally never only one way to solve a specific problem. Storing your animal data in a dictionary or a data format is completely valid. Programming is often about finding the most efficient solution for a problem.
Learning about OOP is somewhat essential in GameDev though, I do recommend learning about classes and such.

BE-Never Games | 2018-07-07 21:50

But man, json is a pretty comum format to save stuff in a quick and easy way. Why just don’t let developers use it?! Just cant understand whats the big deal with it.

Leonardo Da Vinci | 2019-02-12 02:43