Function is doesnt run

Please share source code as text. You can add preformatted text using the </> or using three back ticks on a separate line.

The problem is that you are not properly providing a callback function:

self.druid:new_button("button_1", usual_callback("sdfgh"))

Let’s break it down into individual pieces. You have two arguments, a string and a callback function. The below is equivalent to what you wrote:

local s = "button_1"
local fn = usual_callback("sdfgh")
self.druid:new_button(s, fn)

Notice that you are calling the function usual_callback and not providing it as an argument. The variable fn will be assigned the return value of usual_callback, not the function itself. And the function is not returning any value, which means that it will be nil

local s = "button_1"
local fn = nil
self.druid:new_button(s, fn)

What you want to do is this:

local s = "button_1"
local fn = usual_callback
self.druid:new_button(s, fn)

self.druid:new_button("button_1", usual_callback)
2 Likes

image

I want to if click to 1 insert 1 in Text.

Sample:
Click 1=> Text1
Click 2=> Text11

local druid = require("druid.druid")
local input = require("druid.extended.input")
druid.register("input", input)

local inputa
local yazi

local function usual_callback()
	inputa.set_text(inputa, "Text")
end

function init(self)
	msg.post(".", "acquire_input_focus")
	self.druid = druid.new(self)
	self.druid:new_button("button_1", usual_callback)
	inputa = self.druid:new_input("input_box_numpad", "input_text_numpad", gui.KEYBOARD_TYPE_NUMBER_PAD)
end

function final(self)
	self.druid:final()
end


function update(self, dt)
	self.druid:update(dt)
end


function on_message(self, message_id, message, sender)
	self.druid:on_message(message_id, message, sender)
end


function on_input(self, action_id, action)
	print("Corretc")
	return self.druid:on_input(action_id, action)
end

Well, I suppose you need to get the current text in the field, or store the text in a string variable and concatenate a “1” to the string before setting it?

This code doesn’t seem right. It should be inputa:set_text(inputa:get_text() .. "Text") if you want to concatenate.
Looking at your samples, I think you want like this:

inputa:set_text(inputa:get_text() .. "1")

thanks.

i want write button text.

1 2 3 4

if click 4 write 4

Looks like this is just your testing stuff. Actually you can do it by using a counting variable and doing a concatenation on clicking. It’s easy if you knew the basic lua functions & syntax

not working

image

                            for i = 1, 10 do
				timer.delay(0, false, function()
					local node = gui.clone(prefab)
					gui.set_enabled(node, true)
					grid:add(node)
				end)
			end

text on prefab not showing in build.

Of course it’s not working. You are writing wrong lua syntax.

this will work

self.druid:new_button("button_1", function()
    usual_callback("sdfgh")
end)

also remember to change the inside function content by

inputa:set_text(inputa:get_text() .. str)

i want to

    self.druid:new_button("button_1", function()
    usual_callback(str)
end)