[SOLVED] Reading data from file, use to work on GD4

Hi everyone,

This use to work on GD4:

And the exact same thing doesn’t work on GD5:

the “random_lines.txt” look like this:
gdtxt

Can you tell me what went wrong?

My project is for mobile, I would like to read data from an external file (not accessible once the game is compiled): there is a lot of data and not everything is needed all the time so I don’t want to overload the project by setting a ton of variable up.
I just want to get my data when needed.

I don’t mind the format or structure of the file, I will deal with it.
I’ve understood that I won’t be able to write inside the file but I will use the Storage if I need to write something, I’m ok with that.

Can you help me get something similar done with GD5? Working on Mobile?
Thanks!

Hey! As the native platform got deprecated, the storage now uses actions from the Javascript/Web platform. The web cannot directly interface with the filesystem (imagine if scam websites could read all your data?) like before, so the storage extension now uses cookies. It’s exclusively for Storing data, that means it starts as a clean “filesystem simulation” with nothing on it. You can read and write it but you cannot use it to access existing files.

To access the filesystem on computers running the executable version a new extension have been created, the Filesystem extension. Unfortunately it doesn’t support (yet?) mobile filesystem.

Until an extension to load project files on android too get created, a workaround would be to convert your file to json, load it as a JSON resource, and load it with the network extension (just type the filename with extension as the url, no protocol, slashes or anything else), and use the action to convert JSON to a variable.

2 Likes

Hi!
Thank you for your thorough answer.

I tried to figure something out of this, it goes as follow:

actions

inside the Send GET request it goes like this
insideaction
and my json file looks like this:
supetotal

Annnddd that doesn’t work… Can you help me figure this out?

Well I’m still trying to make this work…

Removed the “/” before the name of my file, I tried to change the structure of my json file to this:
“null” :
“[{ “first”: 12,“second”: 66,“string”: “nothing”,“structured”: { “ChildVariable”: 1,“ChildVariable2”: 2,“ChildVariable3”: 3,“ChildVariable4”: 4 } } ]”

(I tried to be inspired by this guy )

But still no chance, even the temp_json variable returns a sad “0”, just like it is not even looking at the json file…

Something must be wrong…:disappointed_relieved:
Even the simpliest thing:


simpleton

with the file weapons.json being this one (proven to be a good json):
https://pastebin.com/v0jRuWun

And the debugger gives me a big:
fat

Is that a problem on my computer? I mean, this seems pretty straightforward, isn’t it?
Thank you for your help

If I put the json on my desktop, this:


does work…

But it won’t work on mobile obviously…
So why it doesn’t work if I put the name of the file alone while being in my project folder

Make sure the json file is being exported too. Try to add it as a json resource somehow (maybe by putting them in a yarn event?)

1 Like

Thanks arthuro, I figured it out.
I think I’ll make a quick tutorial in the next days to help people who have the same issue as I had.
I’ll put a link to the tutorial here so please don’t SOLVE it yet.
Best,

1 Like

Seems like you got it working. Can you please tell me how yo solved this?

1 Like

Sure, I’m gonna make a tutorial for this very soon

Thank you. I managed to solve it already by following arthuro’s advice. It works!

Sweet, sorry I took so long to answer.
I’ll make a tutorial anyway, looks like it’s finally not such a rare problem and for someone totally new to game dev, it ain’t easy.

1 Like

I figured it all out, so there you have it, I made a tutorial about how to do this: