Calling a popup using a button

objectiveness is not related to talking about everything;

second, an introductory tutorial should not talk about everything an engine does, but as I said, the basic. it also teaches you how to use and instantiane multiple scenes, which help for what you wanted: show the popup when the button is pressed. just instantiate it when pressed, then queue_free() it when closing, either that or hide() and show() the popup as a child of thr button.

also, tip: don’t show screenshot of code, just send the text formated inside ```, which makes the text monospaced in the forum and easy to read. you can send an image of the scene tree.

1 Like

I would follow undones advise . The tutorial mentions prerequisites so do that first.

Prerequisites¶
This step-by-step tutorial is intended for beginners who followed the complete Getting Started.

https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html#toc-learn-step-by-step

I took these courses and there is nothing like them THANK YOU!

1 Like

is your problem solved? if so, you may mark the post as solved and mark the reply which solved your problem :slight_smile:

1 Like

You read the message incorrectly, the problem is not solved, but I’m trying to do something about it

I didn’t suppose it is solved, I was asking ^^

well, you can get a node with $path_to_subnode or get_parent().get_node(‘nodepath’) for a sibling node, so you can make the popup as s child of button, and when the button is pressed (verified by the “on_pressed()” signal), you can do something like:

if $popup.is_visible() == true:
  $popup.hide()
else:
  $popup.show()

you may want to make a function out of it, if you use it too much:

func toggle_visibility(whose):
  if whose.is_visible() == true:
    whose.hide()
else:
  whose.show()

then just call it:

toggle_visibility($popup)

1 Like

So, in the first case, before the script, I added a pressed signal and then the script, the console did not show any errors, but when I pressed the button, Godot crashed. In the second script, the console asked to add a pressed signal, but I couldn’t do it because the space was already occupied by the function toggle_visibility , After pressing the button nothing happens. :weary:

but I couldn’t do it because the space was already occupied by the function toggle_visibility

which space?

could you copy and paste the code here?

I just corrected my last post from toggle($popup) to toggle_visibility($popup), I hope you’ve chatched that in time

1 Like

The engine prohibits having two functions

Because it’s on the first line Toggle_visibility Then I can’t add a signal pressed

func toggle_visibility(whose):
if whose.is_visible() == true:
whose.hide()
else:
whose.show()

It’s clear :frowning_face:

could you put it in a code block? it is good practise to always put code in code blocks, they write like this:

```
code here
```

and they would appear like this:

code here

is your code properly indented? it does not seem to be from your message.

also, I don’t get what you mean by ‘the engine prohibits having two functions’, it does not, you can have any amount of functions in a script.

you said the first line is toggle_visibility, did you remove ‘extends X’, where X is the class of the node?

you don’t need to add the ‘signal pressed’ manually, signals are on the rightmost, by side of the inspector, in the Node tab, just click on the signal you want, and the node with the script you want, and Ok, it will add the signal. you don’t need to write ‘signal _signal_name’

if you remove the signal’s function, make sure to disconnect it from the node tab

1 Like

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

you insert what the button will do on the indentation of the _on_button_pressed() signal you showed in the picture.

did you write the function inside a function? if so, write functions apart, like this:

func toggle_visibility(whose):
  if whose.is_visible() == true:
    whose.hide()
  else:
    whose.show()

func _on_button_pressed():
  toggle_visibility(nodeName)
1 Like

I AM SHOCKED, EVERYTHING TURNED OUT TO BE SO MUCH EASIER!! WHAT I THOUGHT, now I’ll show you

1 Like

Look at this screen Namely on line 7
It’s written there`

Func_on_button_pressed

Most likely he wrote the code for Gobot 3, and I use Godot 4 And this line should be written correctly like this

Func_on_pressed 

That’s the whole solution, but another problem has appeared, I’ll show you now

This artifact appeared

I sincerely apologize for wasting your time and appreciate your help.

that should be, in fact:

func on_pressed()

func defines a function, it should not be part if thef function name :slight_smile:
also, don’t forget the () after the function name!

that’s the window you created with the code on on_pressed()

you should be able to press F10, or “Help”, and search for stuff;

search the Popup properties (just “Popup”, open it, and it will open everything about it). search for an equivalent for the title and text. I believe it should be just title and text, but check it out first :slight_smile:

thenj just define w.title and w.text

Okie :slight_smile:

No problem, I understand your confusion as a beginner. After work, provide more details on what you’ve tried so far, and I’ll be happy to walk through creating the pop-up window step-by-step in a friendly manner.