I am generating buttons for players with this code.
for _, data in pairs(players) do
local nodes = gui.clone_tree(player_label)
pos.y = pos.y + off_set_y
gui.set_position(nodes[hash("remove_user_button/buttonBody")], pos)
gui.set_text(nodes[hash("remove_user_button/text")], data)
local button = self.druid:new_button(nodes[hash("remove_user_button/buttonBody")])
button.on_click:subscribe(function() remove_user_buttons(self,button, data ) end)
end
The Idea is that I add all the players with buttons dynamically added then be able to selected the player I want to be removed. Which I can get to work but the problem I have that I can’t seem to figure out is that now. Is after I am done selecting the users and leave the screen the dynamic buttons remain.
would I have to put all the buttons in a table maybe and delete them that way? Or is there an easier way to do this that I am not seeing.
Thanks for the reply! I do know I can delete the node with gui.delete_node(node) I can do once it it is clicked. But I would have to click all of them for them to disappear. I was looking for a way to just remove them after they have been created. And the user selected is deleted.
here is how I am leaving the screen after displaying the buttons.
local function okay_callback(self)
msg.post("main:/remove_user#remove_user_prompt", "Hide")
-- code to remove users goes here
-- clean up dynamic buttons
end
gui.set_id(nodes[hash("remove_user_button/buttonBody")], "body_" .. data )
which set the node so I could call them later to delete them like this.
local remove_button = gui.get_node("body_" .. removed_player)
gui.delete_node(remove_button)
this deletes the node but I get and error from druid it looks like?
ERROR:SCRIPT: /druid/helper.lua:161: Deleted node
stack traceback:
[C]:-1: in function is_enabled
/druid/helper.lua:161: in function is_enabled
/druid/base/hover.lua:49: in function on_input
/druid/system/druid_instance.lua:155: in function process_input
/druid/system/druid_instance.lua:303: in function </druid/system/druid_instance.lua:297>
ERROR:SCRIPT: /druid/helper.lua:161: Deleted node
stack traceback:
[C]:-1: in function is_enabled
/druid/helper.lua:161: in function is_enabled
/druid/base/hover.lua:49: in function on_input
/druid/system/druid_instance.lua:155: in function process_input
/druid/system/druid_instance.lua:303: in function </druid/system/druid_instance.lua:297>
here is how I am generating it and then the call to delete it.
-- loop though player table and make buttons
for _, data in pairs(players) do
local nodes = gui.clone_tree(player_label)
pos.y = pos.y + off_set_y
gui.set_position(nodes[hash("remove_user_button/buttonBody")], pos)
gui.set_text(nodes[hash("remove_user_button/text")], data)
local button = self.druid:new_button(nodes[hash("remove_user_button/buttonBody")])
button.on_click:subscribe(function() remove_user_buttons(self,button, data ) end)
gui.set_id(nodes[hash("remove_user_button/buttonBody")], "body_" .. data )
end
delete button
-- cycle though removed players and delete their button
for _,removed_players in pairs(self.removed_buttons) do
local player_index = get_player_index(removed_players)
local removed_player_button = gui.get_node("body_" .. removed_players)
local remove_button = gui.get_node("body_" .. removed_players)
gui.delete_node(remove_button)
end
I will see if I can debug this but this is what I was able to figure out on my own.
If you create some Druid component and want to remove it (except all gui scene is removed), you should use self.druid:remove(instance)(Defold Druid UI Library). And you still need to remove gui node like you doing this.