Gooey help (SOLVED)

Hello! I very recently started learning Defold and, being a complete and total noob in Lua I wondered if there is a GUI library, and to my relief there are a couple. I decided to go with Gooey since it seems to support quite a few GUI elements. I added it to my dependency list and followed their example to make a button but it didn’t work for me. My steps were as follows…

  1. Make a new GUI file
  2. Insert a button template node from gooey
  3. Attach the example button script (see below)
  4. Add the GUI file to the main collection

And that didn’t seem to work (the console didn’t print anything), and here’s the example script I used if it helps:

local gooey = require "gooey.gooey"

local function update_button(button)
	if button.pressed_now then
		gui.play_flipbook(button.node, hash("button_pressed"))
	elseif button.released_now then
		gui.play_flipbook(button.node, hash("button_normal"))
	elseif not button.pressed and button.over_now then
		gui.play_flipbook(button.node, hash("button_over"))
	elseif not button.pressed and button.out_now then
		gui.play_flipbook(button.node, hash("button_normal"))
	end
end

local function on_pressed(button)
	print("pressed")
end

function on_input(self, action_id, action)
	gooey.button("button/bg", action_id, action, on_pressed, update_button)
end

Any help with this would be appreciated - and I mean any, tell me where I could’ve went wrong, ask me what I did etc. I am just a noob after all. :smiley:
Thank you in advance!

1 Like

Hi, i never used Gooey, but i was looking at their asset portal page and i thought maybe you forgot to do this :

For Gooey to work it requires a couple of input bindings:
Mouse trigger - mouse-button-1 -> touch
Mouse trigger - mouse-wheel-up -> scroll_up (for scrolling in lists)
Mouse trigger - mouse-wheel-down -> scroll_down (for scrolling in lists)
Key trigger - key-backspace -> backspace (for text input)
Text trigger - text -> text (for text input)
Text trigger - marked-text -> marked_text (for text input)

1 Like

Thanks for the reply! I did do all the necessary bindings however, so that’s not the issue.

2 Likes

The script will need to acquire input focus to receive input.

function init(self)
	msg.post(".", "acquire_input_focus")
end
4 Likes

I feel dumb now… Thank you for the reply! :smiley:

4 Likes

Good that you solved the problem!

If you use one of the provided themes then you need to do even less in your gui script. Here’s an example with the RPG theme of buttons:

local rpg = require "gooey.themes.rpg.rpg"

function on_input(self, action_id, action)
	rpg.button("button", action_id, action, function(button)
		print("pressed button")
	end)
end

Notice that there is no need for you to change button visuals when you use a theme. It will be taken care of for you. If you want to create a custom theme specifically for your game then follow the setup done in rpg.lua or one of the other provided themes.

2 Likes