Need help using Defold-Ink for Dialogue

I’m working on a small project that requires branching dialogue. I’m somewhat familiar with Ink and Inky so I was very happy there was an extension for it available. I tried Narrator, but it just didn’t click and Defold-Ink seemed like it might be easier to work with.
So far, I have managed to make it display the ink story and options on a gui (shown in the image)


but I can’t seem to wrap my head around how to make it select and display the options a player chooses. The template project that is available is massive (for me); a few hundred lines of code that also showcase widgets and other features. It’s a bit overwhelming!

Does anyone have any experience, or can give me some insight on how to change the story after a choice is made? This is the code I used to get to this point:

local ink = require "ink.story"
local shrink_node = vmath.vector3(0.9)
local normal_node = vmath.vector3(1)

function init(self)
	msg.post(".", "acquire_input_focus")
	self.choice_set= false
	-- Parse a story from the JSON file. Make sure it's UTF8!
	local res = sys.load_resource("/assets/new_test.json")
	local story = ink.create(res)

	-- Begin the story
	local paragraphs, answers = story.continue()

	-- Output text to the player
	for _, p in ipairs (paragraphs) do
		local node = gui.get_node("title")
		gui.set_text(node, p.text)
		pprint(p.text)

	end

	if #answers > 0 then
		for i, a in ipairs (answers) do
			pprint("[" .. i .. "] " .. a.text)
			local current_option_node = gui.get_node("option" .. i)
			gui.set_text(current_option_node, a.text)
			-- gui.set_text(gui.get_node("option2"), i .. a.text)
		end
	end

	-- Send answer #1 to the story to generate new paragraphs

	paragraphs, answers = story.continue(1)
	
	
end

function on_input(self, action_id, action)
	for i = 1, 3 do
		local current_option_node = gui.get_node("option" .. i)
		if gui.pick_node(current_option_node, action.x, action.y) then
			if action.pressed then
				gui.set_scale(current_option_node, shrink_node)
				
			elseif action.released then
				gui.set_scale(current_option_node, normal_node)
				
			end
		end
		
	end
end

I think Ivan_Lytkin is the author of the Defold-Ink extension. Maybe he can help? Did you also check the template project (Visual Novel ink template)? Is it working for you?

I haven’t checked out that template yet, thanks for the heads-up! I’ll check it out and see whether it’s beginner friendly or if I can get some additional insight into how to make Defold-Ink work.

1 Like