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!
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
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.
Thank you so much! I’m glad it’s useful! I even adopted it to create a quest flow for my game! I might release a new version of Defork in the future, when I will be refactoring it for my own project