combining and func and an If in one line of code???

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Theducksrage

I’m trying to get it so that when and area2d enters the collision shape AND the If Input is pressed then this happens do you know how to do that

:bust_in_silhouette: Reply From: PunchablePlushie

Not sure if this is the best/efficient way of doing this but you could use the _process() function. Any code in the function is executed every frame and you can enable or disable it using set_process().

The code could look something similar to this:

func _ready():

func _process(delta):
    if Input.is_action_just_pressed("next"):
        # Do stuff

func _on_Area2D_body_entered(body):

func _on_Area2D_body_exited(body):

Note that when you override _process() in your code, processing gets enabled automatically, so if you want the object NOT to start processing right off the bat (AKA when it gets created), you should disable it in the _ready function.
So we disable _process() in the beginning. When the body enters the shape, we enable _process and listen for input. When the body leaves, we stop _process().