Defold build HTML5 can not read/create file *txt

I have created one file *txt and handle it on Defold. I build and debug on win32, it works normally. But when I export to HTML5 application then my app not work. And the log error “Failed to load resource: the server responded with a status of 404 (Not Found)”. Who can help me with this issue? Thanks all.

1 Like

How? What do you mean by handle it?

If you load it using for instance io.open() and read() then yes, that will most likely work on windows if the .txt file is located next to the engine. But on HTML5 the file is not present. It’s still on your hard drive where the browser isn’t able to load it.

If you wish to bundle additional files then I recommend that you use the Custom Resources setting in game.project and sys.load_resource().

Hi, thanks for your answer.
I use io.open () and read () it. The .txt file is located next to the tool and works normally on win32.
So, how to use custom game settings in the game.project and sys.load_resource (). If you have an example of this, then that’s a great thing.

Here’s the docs:

Custom Resources: https://www.defold.com/manuals/project-settings/#_project
sys.load_resource() incl. example: https://www.defold.com/ref/sys/#sys.load_resource:filename

3 Likes

Thanks so much



I have check with example, but it return error as image. Do you have know this issue ?

I think you need to write the full path.

sys.load_resource("/main/data/assets/accounts.json")
2 Likes

Yes, exactly. Full path like in the example.

2 Likes

Hi,
Thanks so much. I loaded it success

@britzl I’m writing HTML5 app can read a file “Replay.txt” and display it.
If I use sys:load_resource when build HTML5, this file does not appear in folder, does it has zipped somewhere?
Do you have any solution for this?

Resources that are included as Custom Resources will be included in the engine game archive (one of the game.arcd files in the archive folder).

1 Like

Thank @britzl, Is there anyway to read a file “a.txt” near index.html or anywhere possible?
I’m in a dead-end.

Yes, you can use Bundle Resources instead to include files next to your engine. On desktop platforms you will be able to use io.* functions, but on HTML5 that will obviously not work. On HTML5 you can do http.request() to get the file.

1 Like