Defold build HTML5 can not read/create file *txt

#1

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

#2

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().

0 Likes

#3

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.

0 Likes

#4

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

#5

Thanks so much

0 Likes

#6



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

0 Likes

#7

I think you need to write the full path.

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

#8

Yes, exactly. Full path like in the example.

2 Likes

#9

Hi,
Thanks so much. I loaded it success

0 Likes

#11

@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?

0 Likes

#12

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

#13

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

0 Likes

#14

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