Calling a popup using a button

One of the users sent me this code

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():
	view_port=get_window()
	w=Popup.new()
	w.borderless=false
	w.unresizable=false
	w.size=view_port.size * 0.5
	w.position=(view_port.size - w.size) * 0.5
	w.exclusive = true
	w.popup_window=false
	w.name="popup"
	w.visible=true
	w.transient=true
	
	popup = PopUpScene.instantiate()
	popup.position=Vector2i(0,0)
	popup.size=w.size
	
	w.add_child(popup)
	w.close_requested.connect(func():w.hide())
	view_port.add_child(w)

	pass # Replace with function body.

I requested help from the user “canceled” and we realized that the function was not called correctly and fi

Forgive the mistakes, I’m from Russia and don’t know English well

We fixed the function and the code started working

But when I launched the scene and clicked on the button, I saw that my pop-up window appeared, but for some reason a second one was created, as you can look at the pictures

I looked at the code and realized that it not only calls my window, but also creates a new one. I have 9 extra lines of code, but the second window is still being created, only it has become smaller in size

extends TextureButton

@onready var PopUpScene:PackedScene = preload("res://сцены/параметры.tscn")
var popup:Control
var w: Popup
var view_port:Window
func _on_pressed():
		view_port=get_window()
		w=Popup.new()
		w.visible=true
		w.transient=true
		popup = PopUpScene.instantiate()
		popup.position=Vector2i(0,0)
		popup.size=w.size
		w.add_child(popup)
		w.close_requested.connect(func():w.hide())
		view_port.add_child(w)

I would be grateful if you would remove what creates the second window :slight_smile:

Ps : What is this link you provided? Your company? (no need to answer)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.