"misplaced func" even though nothing appears to be wrong

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

on line 28 of this script, i added a timeout() signal from a timer node, but it says that this is an “error parsing expression: misplaced func”. i’m not sure why this is happening, however. can someone help? script:

extends KinematicBody2D

var UP = Vector2(0,-1)
var dashes = 1
var motion = Vector2()
var right = true

func _physics_process(delta):
	motion.y += 20
	
	if Input.is_action_pressed("ui_right"):
		motion.x = 200
		right = true
	if Input.is_action_pressed("ui_left"):
		motion.x = -200
		right = false
	if Input.is_action_just_pressed("ui_dash"):
		if dashes == 1:
			dashes = 0
			motion.y = 0
			$Dash.start()
			
			if right == true:
				motion.x = 600
			else:
				motion.x = -600
				
			func _on_Dash_timeout():
				motion.x = 0
				pass 
	
	if is_on_floor():
		dashes = 1
		motion.y = 0
	motion = move_and_slide(motion,UP)

Edited to fix code formatting. Please use the “Code Sample” button when pasting code so that it is formatted correctly.

kidscancode | 2021-06-28 16:20

:bust_in_silhouette: Reply From: kidscancode

Your indentation is wrong. Functions can’t be declared inside other functions.

The line that reads func _on_Dash_timeout() should not be indented at all. I also suspect it belongs at the end, not in the middle of your movement code.