Dirty Larry GUI Questions from a GUI Noob (SOLVED)

First off, Hello! I’ve been lurking for about a month now and trying to get my feet wet. I’ve gone through the Getting Started Project and love what I see so far.

I found the Dirty Larry GUI library and thought it would be fun to tinker with since my future projects will likely have the need for several input formats like this. I ran into an issue almost immediately that I don’t know where to look to resolve.

Basically it’s duplicating keystrokes for the text input. Even backspace.

My gui script

local dirtylarry = require "dirtylarry/dirtylarry"

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

function on_input(self, action_id, action)
    self.input_default  = dirtylarry:input("main_text", action_id, action, gui.KEYBOARD_TYPE_DEFAULT, "Default text")
	print(dirtylarry:input("main_text", action_id, action, gui.KEYBOARD_TYPE_DEFAULT, "Default text"))
end

Any ideas? I’ve read the GUI manual but, like I said I’m new so I could be missing something obvious.

Thanks!
-Josh

Hmm. My first thought is that it is recording the character on press and release. Try limiting the action to one or the other and see what happens.

I was thinking that too, but I can press and hold the key down and it delivers exactly two characters to the text node… before the release.

Hi @jweaver911, and welcome!

You are calling the function twice, thus the key will be repeated twice. The function has side effects, i.e. it’s altering the state of the gui node. If you instead do print(self.input_default) you should get better results.

2 Likes

Yep, what @Mathias_Westerdahl said. In your print() you do an additional call to dirtylarry:input() which will process the action a second time.

1 Like

Ha! so it was something obvious.That totally makes sense. Thanks guys.

Got another easy one for you guys on Dirty Larry.

How would I update a field programmatically. More specifically, how would I clear the input text after use.
Do I pass a message to the same script like below? And if so, then what. I didn’t see a “clear input” function in the dirty larry code. Do I need to manually set the text node?

Thanks guys,

function on_input(self, action_id, action)
    self.input_default = dl:input("main_text", action_id, action, gui.KEYBOARD_TYPE_DEFAULT, "Default text")
	
	if action_id == hash("submit") and action.released == true then
		print("Submitted!")
		msg.post("main:/display#display", hash("update_text"), { value = self.input_default })
		msg.post("#", hash("clear_field"))
		pprint(dl)
	end
end

You should use gui.set_text() to clear the field. If you look at the “main_text” input field or any other text field provided by Dirty Larry for that matter you see that it is created from a gui template, and if you expand the node hierarchy you can see that it looks like this:

It is a nested hierarchy of gui nodes, mostly box nodes with images, but there is also an inner text node, in the picture above named “main_text/content”. The DirtyLarry library handles forwarded input actions and in the case of text input it manipulates the content of the text node.

You should be able to do gui.get_text(“main_text/content”) to manually get the text in the text field and you can use gui.set_text(“main_text/content”, “”) to clear the text.

It is important to understand that Dirty Larry simply operate on gui nodes with the API functions available for gui scenes. Dirty Larry adds quite a bit of convenience when working with text input, buttons etc, but there really is no magic to it. You can do all of it yourself with the gui.* functions and it is a good idea to learn the raw gui system as well to better understand how Defold works.

1 Like

I see! I was headed down that route of updating the GUI node but didn’t realize I needed to call

gui.set_text()

On the inner nested node. That was where I was getting hung up.

My goal in this exercise was updating a separate text node upon enter key usage, which I have working :slight_smile: