0 votes

Hi everyone, my

func _process(delta):
    timer += delta

    and then some ifs

works wonderfully when clicking anywhere on the screen. Now I'd like it to react only within an Area2D, so I put all the ifs into a func _on_HoldButtonBase_input_event(viewport, event, shape_idx):. But then it doesn't work right anymore (in my case, for some reason I have to move the mouse around within the CollosionShape2D to have everything work, but there are flaws if I hold still...).

Now my abstract thought is: What if I could put the whole func process(delta): "into" the inputevent-function? Shouldn't then everything be fine?
Alas, I wouldn't know how to achieve this. Any ideas?

in Engine by (508 points)

1 Answer

+1 vote
Best answer

First, no, you can't put the _process() function inside another function.

Assuming this question is related to the "timer chaining" question we worked on earlier, here's one idea.

Why not simply connect the mouse_entered and mouse_exited signals of your Area2D. In those signal handlers, just set a simple boolean flag indicating whether the mouse is currently inside the Area2D. For example, mouse_over_button = true in the mouse_entered and ... = false in the mouse_exited.

Then, use that flag to skip the code you have in _process if the value is false?

As I mentioned in the other thread, there are lots of ways to do the same thing. While this might not be the cleanest overall (based on a better understanding of what you're doing), it's probably one of the easier ways to get from what you have to what you want...

by (21,864 points)
edited by

Another simple way my beginner-mind couldn't come up with yet. This does the trick! Thanks again, Jgodfrey!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.