How to make something pop up when pressing a button?

hey guys. im very very new to godot and i want to make a point-and-click game as a start. I am also VERY new to coding as well.

my issue right now is trying to make as a button, where when you click on it a phone appears. the phone also has a back button to go back to the main game. when i tested it out it still shows the phone and instead the back button gets hidden. here is my code and work-in-progress (ill change the assets later when all code is finalized)

thank you for your time! ^^

First of all i suggest to use the new “connect”-syntax:

game.get_node("phone_icon_button").pressed.connect(_on_phone_pressed)

Also you shouldnt call the $PhoneIcon-variable the name “game” when your script already is the game.

you are calling “show” and “hide” on the “phone”-variable. But the “phone” variable is only a reference to the back_button-node and not to the phone.
This misunderstanding is why you should name your variables accordingly to what they are supposed to hold.

Try something like this:

@onready var phone_icon_button: Control = $PhoneIcon/phone_icon_button
@onready var phone: Node2D = $PhoneIcon/phone

func _ready():
    phone_icon_button.pressed.connect(_on_phone_pressed)
    phone.get_node("back_button_phone").pressed.connect(on_back_button_pressed)

func _on_phone_pressed():
    phone.show()

func _on_back_button_pressed():
    phone.hide()

thank you! but now its having an error where it says “invalid access to property or key ‘pressed’ on a base object of type Control” :frowning: any tips?

is “phone_icon_button” a Button-Node? Can you show the scenetree of “Phoneicon” and “phone”?

the phone_icon_button is a button node yea, and i can show you the phone node cause itll only let me post one pic apparently

There is no back_button as a child of Phone. Also it looks like “phone_icon_button” is only a control node and not a button. can you somehow show the hierachy with the corresponding node-type?

phone_icon_button has its own scene with a button. i copy-pasted it to the main game. should i try inputting the button in the main game too? I have also tried putting the back button to the phone node but it still didnt work

you need to reference this button-node and connect the signal from it. I dont know where exactly your button node is so i cant help you with the referencing