Problem whe using sys.load_resource in Defork (SOLVED)

Hello! I’m trying to set up Defork in my project, but it fails to load the dialogue file
I’m using the following code from the examples:

local dialog = defork.load("/assets/dialog.json")

In the defork file:

function M.load(resource)
	print(resource)
	local data = sys.load_resource(resource)
	print(data)
	dialog_data = json.decode(data)

I get the following output:

DEBUG:SCRIPT: /assets/dialog.json
DEBUG:SCRIPT: nil
ERROR:SCRIPT: /defork/defork.lua:22: bad argument #1 to 'decode' (string expected, got nil)
stack traceback:
	[C]: in function 'decode'
	/defork/defork.lua:22: in function 'load'

If I click the path, it gets me to the right file. What’s the problem?
Thank you!

If you read the documentation for sys.load_resource, you’ll notice that it mentions custom resources.

Since the Defork repo doesn’t mention it, my guess is that you haven’t setup the folder to be bundled as custom resources?

See the Defork example here

Perhhaps @Pawel could add this info to the “how to” in the github repo?

2 Likes

Works just fine after setting up custom resources. Thanks a lot! This should definitely be in the “how to”.

2 Likes

Thanks for answering @Mathias_Westerdahl! Indeed, such info should be added there, I’ll fix it right now!

EDIT:
There was:

To add use custom json data file type it in game.project, e.g. if you have you file in assets folder in project directory type: assets/dialog.json

But I will change it to something more clear:

Then you need to add dialogs exported from Twine in a JSON format (using Twinson - details below) to your project. To add it, you need to provide a path in [Custom Resource] field of your game.project in Defold. For example, if you have your file in the assets folder in the project directory, type: assets/dialogue.json. You can find more informations about custom resources in official Defold’s documentation here.

I took a chance to check and update whole documentation and added examples for functions and Defold Printer option as well :wink:

4 Likes

Great! I also found it quite easy to join Defork and Printer, even managed to get the choice system to work. The code is somewhat messy now, but I might release it someday in the future. Such an amazing asset.

2 Likes

Thank you so much! I’m glad it’s useful! I even adopted it to create a quest flow for my game! :smile:I might release a new version of Defork in the future, when I will be refactoring it for my own project :wink:

1 Like