Calling a popup using a button

P.S: Gokot 4.2
I need a popup to appear when a button is clicked on the user’s screen, but unfortunately I don’t know what script the button should have. Can you show this with your example? Thank you, I will be grateful.

1 Like

Just set a signal to fire a function on the popup that changes its visibility parameter

Of course, it is logical that a signal is needed to call a function, but what to write next. This is the main problem :3

Just attach a script to the menu and write a function called showUI() or whateber you like and then just do visibility = true in the function body it shouldnt be any more complicated than that other than connecting the signal to that function…

1 Like

Many thanks for the help

Im at work or id write out the code for you. Im off in a few hours let me know if you have any further issues.

Very interesting but nothing is clear, excuse me for my confusion. Look, I have a button, when clicked, a pop-up window should appear. I have two scenes, one is the main one. And the second scene is with a floating window and my problem is that I’m a beginner and some things are difficult for me. I’ll be waiting for your reply after work :slight_smile:

1 Like

I can’t count on your help?

Make two scenes. One MainScene with a Control and add a Button. The other scene called PopupScene file name pop_up_scene.tscn and add a Panel node with some background color and a Label. Attach the script below to the MainScene node and connect the Button pressed() to _on_button_pressed() and run it.

extends Control

@onready var PopUpScene:PackedScene = preload("res://pop_up_scene.tscn")
var popup:Control
var w: Popup
var view_port:Window

func _on_button_pressed():
	w.size=view_port.size * 0.5
	w.position=(view_port.size - w.size) * 0.5
	w.exclusive = true
	popup = PopUpScene.instantiate()

	pass # Replace with function body.

1 Like

Errors. What did I do wrong?

I don’t read code well because I’m from Russia. Sorry for the inconvenience. :face_with_diagonal_mouth:

Everything. Don’t add indentations at your will. Delete all redundant tabs.
Learn more: GDScript style guide — Godot Engine (stable) documentation in English


Thank you

OK. I figured this out, but how to tell the script that the action should be played when the button in the upper left corner is pressed. I didn’t understand here

On the first screen, in my reply, you can see to the right side of the inspector with all the signals a Button can send. pressed() is one of them. You need to right click on pressed() and connect it to the script function by selecting the script and the function.

But you need to find some tutorials on youtube that shows you how make a scene and add a Button and connect it to signals. There should be plenty of them. E.g.

And where to insert the instructions on the button???

I subscribed to the channel, there are interesting topics there :slight_smile:

If you don’t understand what I’m asking or are unable to help, then just write about it, I’ll understand :frowning:

try doing this project first, so you learn the basic:

this way you learn the basics about Signals and NodePaths.

every script is a class, and they do have the method show(), which displays them, and hide(), which hides them, so you can just follow the path of the node you want, and use that method.

you can also use the MenuButton node, but then you will have less power overt the popup itself (as you won’t be able to modulate it, for example)

you can also instantiate the popup scene, as teached on the link I showed up

1 Like

I think this lesson is not objective because it does not talk about all the capabilities of the engine, but still I WILL TRY and I hope that it will be useful thanks…