[SOLVED] Link to external files in a desktop game

Hi guys,
I am making a quiz game. I want the user to be able to customize the game by changing the background image and also edit, remove or add questions. The game will be a desktop app for Windows (but I am developing on a Mac). I have tried the read and write actions but those only create hidden data (within the cache in chrome/electron?). Would it be possible to use an external jpg as background in my game and would it be possible to have all the questions in some kind of text file (xml, txt, csv etc)? I did read about the “File system” in the manual, but I didn’t really understand how it works and if it will solve my problem. Maybe there is a tutorial for that? In that case I didn’t find it, so please post a link if there are any tutorials available.

With best regards

Farid

Hey,
I think you could allow the loading of a jpg file with a predefined name and a json file for the questions.
condition : file or folder exists.

Thanks Gruk!
But how do I load a separate jpg? When i export my game to Windows exe I just get a single exe file with all media “baked” into the exe package and when I export to Windows zip I get lots of files and folders but I cant find any of the jpegs that I have imported to my game.

I didn’t say you should swap the files in Windows Explorer.

For the jpg, it looks like the only type allowing you to change the picture through actions is the panel sprite.


Not sure if that type can fit your bill.
I suppose you can write any path in the Image name, but I haven’t tried, maybe some javascript magic is needed because normally, the resources are predeclared. :confused:
For the path syntax, check out this page: Expressions reference [GDevelop wiki]

For the json, if you use the dialog tree features, load the json path of your choice with the appropriate action. If you don’t use the dialog tree, use the action “Load a scene variable from a json”.

In all cases, the path needs to be written before the game is exported, so the users have to been warned that they need to put their files in such folder with such name, or it won’t work.

Is it somewhat clear? :sweat_smile:

Thanks!
I’ll look into that and see if I understand what to do. I was hoping that it would be possible to just export the game with all the graphics in a separate folder and a relative path from the exe file, regardless of where the folder is. And the same thing with the json file.

Now I have watched and read a few tutorials regarding json and I’m still very confused. I don’t think that I need the Dialogue Tree since the structure of the json is pretty simple and I would rather edit the json from a text editor.

FYI: I will install the project on my clients computers, so I will know what path is used. Actually I just want the json file to be in the same folder as the final exe file. Do I need to write a path in that case?

Is there a simple way to write and load variables from a json file? I tried the following but when I check the file with a text editor it is still empty.

//Farid

Maybe you need to add the path delimiter between the two items of your path.
If the json is in the game folder, you need to point to that path I guess.

Hi again,
I solved it. Here is what I did. First I created structured global variables from the project management menu, like this:

Then I loaded a text (string) to the variable structures, like this:
image

Since I couldn’t find an action that saves Global variables to JSON i created scene variables equivalent to my global variables. Maybe I could have created a scene structure from the beginning? I’ll try that later. Anyways, this is how I did it:

One problem though, I managed to save a variable to a JSON file, but not save a structure. I guess I should use some kind of ToJSON command, but I don’t really know how to use it.

Thanks!

Now I have solved it and it seems to be the simplest solution I have seen. I don’t need to parse or anything else :slight_smile:

1 Like