Expected indented block after lambda declaration.

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

I’m trying to make a weapon shoots with left click but the script has this problem

(“Expected indented block after lambda declaration.”)

that’s the code i used to make left click shoots

func _physics_process(delta):
if Input.is_action_just_pressed("left click") else Gun.shoot()
:bust_in_silhouette: Reply From: jgodfrey

That code, as posted, has some problems. That said, exactly as posted, you should be getting a different error. Specifically…

Expected indented block after function declaration

That’s because the 2nd line isn’t indented. If I properly indent that line, then I get:

Expected ":" after "if" condition. That’s because your if block is wrong.

If I add the missing : char (so, this):

func _physics_process(delta):
	if Input.is_action_just_pressed("left click"): else Gun.shoot()

I then get Expected statement, found "else" instead. That’s because there’s no statement to associate with the if side of the logic. Changing that to something like this:

func _physics_process(delta):
	if Input.is_action_just_pressed("left click"):
        print("Left click!")
    else:
       Gun.shoot()

… eliminates all of the errors, assuming the Gun variable has a valid reference in your script…