Error parsing expression, misplaced: elif

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

func _physics_process(delta):

motion.y += gravity 
var friction = false 

if Input.is_action_pressed("ul_rigth"):
   sprite.flip_H = true
   animationPlayer.play("walk")
motion.x = min(motion.x + moveSpeed,maxSpeed)

elif Input.is_action_pressed("ul_left"):
  sprite.flip_h = false
  animationPlayer.play("walk")
  motion.x = max(motion.x - moveSpeed,-maxSpeed)
:bust_in_silhouette: Reply From: jgodfrey

The issue is with this line:

motion.x = min(motion.x + moveSpeed,maxSpeed)

Notice that its indent level matches that of the previous if block. That effectively ends the if block so the following elif no longer makes sense.

I’m not sure what your intention is there. If that motion.x line is intended to be part of the if logic, indent it to indicate that. If it’s not part of the if logic, then it shouldn’t be there at all and needs to be moved to wherever is appropriate.