![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | k2sgaming |
Hi.
I’m having an issue trying to understand the ButtonGroup logic, totally new to GDScript, don’t have a clue of what I’m doing. Obviously is wrong.
I created a scene that I saved in a folder called “Interface”, here is how it looks. Sorry, I know it’s probably messy:
The scene is called “MenuButtons” and it looks as follow:
The GDScript attached to the scene looks as follow:
extends Control
export(ButtonGroup) var group
func _ready():
print(group.get_buttons())
for i in group.get_buttons():
i.connect("pressed", self, "button_pressed")
func button_pressed():
var pressed_button = str(group.get_pressed_button())
var split_text = pressed_button.split(':')
var button_method = str(split_text[0])
print(button_method)
if button_method == "NewGameButton": print('Restarting the game')
if button_method == "OptionsButton": print('Opening the Options screen')
if button_method == "ExitButton": print('Quiting the game')
When I execute the scene with F6 everything works as expected:
Still not what I’m expecting, but it prints something. But here is the situation, I instantiated the MenuButtons scene as a node in another scene called GameOverlay, which is the test game UI.
This scene as well is instantiated inside the Level Scene.
When the Level is run and the Game Over screen shows, neither group.get_buttons() method returns a list and of course the buttons do not initiate the events. It seems to me that the script from MenuButtons does not recognize the button group at all.
I was following two tutorials trying to match their insight about using buttons in Godot. Yeah, I have no idea what I’m doing as you can tell. Any help would be really appreciated.
These are the tutorials I’m following: