Sys.load_resource fails when loading json (SOLVED)

#1

Hey everyone!

For my game (a currently unnamed RPG project) I wanted to create a dialog tree system. For this system I created a custom c# application that exports .json files in the format and with the information I need it to. The problem is that I cannot get Defold to properly load the files at all.

I have checked with an online JSON validator online to confirm that the JSON is in fact legitimate.

The problem seems to be linked entirely with the sys.load_resource() function. Whenever I attempt to use it, I get the error message:
Error: Failed to load resource: /main/level/levelList/SampleNPCArea/convos/sampleConvo1.json (-3) .

I am loading it like this:
local info = “”
local errorText = “”
info, errorText = sys.load_resource("/main/level/levelList/SampleNPCArea/convos/sampleConvo1.json")
return json.decode(info)

I saw in this documentation (https://defold.com/manuals/resource/) that I am suppose to do something with the Custom Resources setting in “game.project”. I have attempted to link the json file to that but it still fails.

I have tried copying and pasting the json file contents into a standard .txt but that fails to load too.

I have tried everything I can think of to trouble shoot. I have no idea that the (-3) means. Any suggestions for what I can try?

Thanks in advance!

0 Likes

#2

I believe the problem is not related to your json file/format. It is probably because of your “Custom Resources” setting is not correct.
Documentation is here: https://defold.com/ref/sys/#sys.load_resource:filename
and
https://defold.com/manuals/project-settings/#custom-resources

custom-resources path should be: main/level/levelList/SampleNPCArea/convos/sampleConvo1.json and afaik it is “case sensitive”.

2 Likes

#3

Finally got around to fixing it and this was extremely helpful! The Custom Resource setting in the game.project file was incorrect, it is working now!

Thank you!

1 Like