Error loading JSON

Hi everyone.Hi there.

In my game, I have to load a JSON file named “letters.json” to use it in a variable.
To try, the JSON file was in the desktop, and I loaded it just like this:

FileSystem::DesktopPath() + FileSystem::PathDelimiter() + "letters.json"

It worked very well.

Then I moved the JSON file in the assets folder, and tried this:

FileSystem::UserdataPath() + FileSystem::PathDelimiter() + "letters.json"
"assets"+ FileSystem::PathDelimiter() + "letters.json"
FileSystem::ExecutablePath()+"assets" + FileSystem::PathDelimiter() + "letters.json"

None of that works… Any ideas?

I would have thought the last one would work. I’d suggest you put that path and filename into a string and either write it out to console or to a text object on screen to check path is correct.

Thanks for answer

The last one shows:
C:\Program Files\GDevelop\GDevelop.exe\assets\letters.json

But it shoud be:
C:\MyProject\assets\letters.json

Or something like that… am I wrong? How I supposed can access to my game/my project folder?

Ah, so that’s the GDevelop executable path.

What happens if you just put in “assets\letters.json”? I’d try it myself but I’ve only got access to the web editor right now, and not the PC editor.

In fact, the JSON file is located in “assets\letters.json”.

I also tried:
FileSystem::PathDelimiter()+"assets"+ FileSystem::PathDelimiter() + "letters.json"

But doesn’t work. In docs I didn’t found something explicit about the paths when you’re editing in GDevelop and when you export the game. Docs about the theme aren’t clear :frowning:

An unsolved issue, maybe?

In the project I’ve got on at the moment, I’ve had to enter the full path. I’m on Windows, storing my project in my documents folder. The path I use to load a json file is "C:\\Users\MrMen\\Documents\\myGame\\assets\\language.json" (yes, double back slash).

I’m not aware of a GDevelop function that returns the current game directory. Maybe raise it as a feature request?

1 Like

I’ll try this… :thinking:

That would be a fantastic feature for desktop games developers… We need it!!!

Thx for answer :wink: