![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | PepijnWe |
I wanted to create a button thas is created in code, but to make it interactive a signal has to be connected wit the .connect function.
I got it working regular as follows:
func _ready():
self.connect("pressed", self, "_on_Button_pressed")
func _on_Button_pressed():
self.text = "OK"
But i want to use it in a class, but then it is not working.
class CreateButton:
var newButton : Button
func _init(_parent, _text)->void:
newButton = Button.new()
newButton.text = _text
newButton.connect("pressed", self, "_on_Button_pressed")
_parent.add_child(newButton)
func _on_Button_pressed():
newButton.text = "OK"
Any help is welkom!
Your class declaration looks fine, but how are you using it? Can you show the code where you instanciate CreateButton
?
Also, what do you mean by “It’s not working”? The button doesn’t show up? Or is it not doing anything when clicked?
Zylann | 2020-03-16 19:57
It creates a button, but the interactive part is not working.
Specificly this section of the code is not running:
func _on_Button_pressed():
newButton.text = "OK"
This is where the function is called
#Displayes list buttons in Grid container Carlist
func displayList(_car):
for i in _car:
#creates Button option
GameData.CreateButton.new(Carlist, "BUY")
PepijnWe | 2020-03-16 20:07