0

Here is the code with the elif statement, this one and elif statements in general. I'm fairly new to Godot and this is me following an example and learning along:

extends AnimatedSprite

func _process(delta):
    
     if Input.is_action_pressed("ui_right"):
      play("Run")
     flip_h = false
     elif  Input.is_action_pressed("ui_left"):
         play("Run")
        flip_h = true
        else:
            play("Idle")
     pass

And I get this error:

error(7,3):Error parsing expression, misplaced: elif

So what could it be? I have no idea how to solve this issue.

yoozer8
  • 7,361
  • 7
  • 58
  • 93

2 Answers2

0

It has to do with how you are indenting your code. Here's a quick look at the documentation.

if, elif and else should all be on the same level of indentation. Everything inside the statements should be indented one additional level. Your code would look like this:

extends AnimatedSprite

func _process(delta): 
  if Input.is_action_pressed("ui_right"):
    play("Run")
    flip_h = false
  elif Input.is_action_pressed("ui_left"):
    play("Run")
    flip_h = true
  else:
    play("Idle")

Also, pass isn't needed at the end because you're calling play("Idle") instead.

JarWarren
  • 1,343
  • 2
  • 13
  • 18
  • 1
    Thank you SO much, I was beating my head on the wall trying to figure it out. Indentation sensitivity is something i have to get used to in Python and the likes. I feel relieved of this burden. I shall thank you again. – Rookie Man Sep 16 '20 at 17:52
0

I have a similar problem

this is my code

elif Input. is_action_pressed("left"):
sprite.flip_h = false
animationPlayer.play("Walk")
motion.x = max(motion.x - moveSpeed,-maxSpeed)

else:
    animationPlayer.play("Itle")
    friction =true
    
if is_on_floor():
    if Input.is_action_press("ui_accet"):
    motion.y = jumpHeigt
if friction == true:
    motion.x = lerp(motion.x ,0,0.5)
else:
    if friction==true:
        motion.x = lerp(motion.x,0,0.01)
        
motion = move_and_slide(motion, up)