Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In node (Menu Button) is not running, the function (is_pressed ()) and in any case returns false ... #5000

Closed
OlexiyKravchuk opened this issue Jun 2, 2016 · 13 comments

Comments

@OlexiyKravchuk
Copy link

In node (Menu Button) is not running, the function (is_pressed ()) and in any case returns false ...

@neikeq
Copy link
Contributor

neikeq commented Jun 2, 2016

It's hard to tell what the issue is about. Could you elaborate a bit more?
Are you expecting is_pressed() to return true when the MenuButton is clicked? If that's the case, did you keep the button pressed the enough time to be sure the state did not get lost between frames?

@slapin
Copy link
Contributor

slapin commented Jun 2, 2016

Somebody just got a get!
Anyway, if node is not running == was not aded to scene, this is normal.
If it is about is_pressed() to return true, you don't want to use that, use signals instead.

button.connect("clicked", self, "_on_button_clicked")

func _on_button_clicked():
   print("Yeeeee!!!")

Should do the trick. If you need to set flag, set it from signal handler.

@OlexiyKravchuk
Copy link
Author

OlexiyKravchuk commented Jun 2, 2016

Of course I spent testing, and the button is clearly working, it can be seen because the pop-up menu appears after pressing, but the function does not return the truth ...

I have a lot of simple (buttons), and in them, this function works properly, but at (menu button) no ...

@neikeq
Copy link
Contributor

neikeq commented Jun 2, 2016

The pressed state is probably list between frames or reset immediately by the MenuButton. Check the following script:

extends MenuButton

func _ready():
    set_process(true)
    set_fixed_process(true)
    connect("pressed", self, "_on_pressed")

func _process(delta):
    if is_pressed():
        prints("_process: is_pressed() is True")

func _fixed_process(delta):
    if is_pressed():
        prints("_fixed_process: is_pressed() is True")

func _on_pressed():
    prints("_on_pressed: is_pressed() is", str(is_pressed()))

In my tests, is_pressed() only returned true inside _on_pressed() (which is the method connected to the pressed signal).

So the correct way is to use this signal, like @slapin mentioned (although he wrote clicked by mistake :P)

@slapin
Copy link
Contributor

slapin commented Jun 3, 2016

Well, anyway, it is better to use signals which is my point.

@OlexiyKravchuk
Copy link
Author

guys let's not deviate from the topic, I have to inform you that there is "door stuck" and you offer me "climb up through the window," but it did not fix the bug, and I need exactly this function, instead of a signal ... =)

@neikeq
Copy link
Contributor

neikeq commented Jun 3, 2016

@OlexiyKravchuk The reason it's not working is because the button loses focus right after clicking it (since the PopupMenu grabs it). When Button loses focus, the pressed state is reset to false.
I don't see a way to change that. It would be easier to explain why exactly you need this method, so we can find a solution (if signal is not the right one for you).

@OlexiyKravchuk
Copy link
Author

@neikeq It is very strange behavior that immediately menu captures focus.
I did my version, in the script (the pop-up menu button), using simple buttons and attached to it a pop-up menu
and as long as I keep the button pressed, menu does not even appear, regardless of duration, and only then release the button pops up a menu, and the function (is_pressed ()) works correctly there ...

But I see another problem in the node (pop up menu) for some reason it does not want to become invisible when I call it a function hide (), and the same problem I see in all nodes inherit from the node (pop up)

@neikeq
Copy link
Contributor

neikeq commented Jun 3, 2016

That's weird. The PopupMenu should appear on mouse pressed, not released (at least it does so for me).

@OlexiyKravchuk
Copy link
Author

OlexiyKravchuk commented Jun 3, 2016

as I said, to work around this problem, I had to invent a "new wheel" instead of using the standard version of the node, but there I got another problem, which is now in the node (popup menu),.
But standard version of node (menu button) works, how it works for you, and this is the problem, it just needs to be fixed so that the menu appears when the button is released, this standard of conduct ...

@neikeq
Copy link
Contributor

neikeq commented Jun 3, 2016

You should have started from there :P
Then this is a feature request. I am not sure what's the opinions of others about showing the PopupMenu on mouse release instead of press, but I guess we could always add a flag for that.

@OlexiyKravchuk
Copy link
Author

@neikeq By the way (option button) works properly and function (is pressed) there, also works great, just as I have described before, and although it is almost the same as the (menu button) but at the (menu button), this functionality is broken ...
Give (option button) a chance to use it as an example of the standard ... =)

@akien-mga
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants