Replacing a button(pressed) with a button made from script

Godot Version

4

Question

So now i have a button(pressed) that when i toggle a checkbox changes the button(pressed) function, but now i need to replace that button(pressed) for a button that it’s created by script.

Screenshot_20240219_105333

Somehow i need a way to replace “$VBoxContainer/Button” with “BTN” that is in the other function.

I recommend exporting both buttons so you can have a reference to both in your script, and not a direct reference to only one object like you have now.

So i removed var BTN = Button.new() and at the top added @export var BTN = Button.new() and it does find the BTN in the checkbox function but now it’s not loading them properly cause it needs to be bellow the for line.

f

Once you include the exports, you need to go back to the godot editor, and manually point your script to the buttons. When you click on the node which has your code, on the right side you will see the two properties for the two buttons.

If you absolutely need to create one button in code, you can still do that and assign it manually to the second variable, but in that case that one doesn’t need to be an exported property.

Well i tried the @export but it’s not what i thought it was so it has to be in the code but then how i assing it to the variable?

Screenshot_20240219_131713

It won’t load like this