Problems with elif, else or if

Hello, I’m incredibly new to coding so try to understand me. I’m making a very simple script for a moving character and the rest of the code works fine, but I can’t solve this part. The person who I’m learning from used ‘else:’ and I tried to change it to ‘elif:’ (tho none worked)…
I also already tried putting the code in the same line as elif but it did not work. Really don’t know what to do now cause this is blocking my progress…

elif:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

When something doesn’t work, divide it into parts and check that each part works

For example, first execute the movement independently, without if or else

velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

Once you’re sure it works, start adding functionality little by little.

add prints to try to see what is happening

if condition:
  print("inside if")
else:
  print("inside else")

print without fear and learn to understand how that works inside

print(a)
print(b)
print(a>b)
if a>b:
  print("inside if")
else:
  print("inside else")

The statement elif must be followed by a condition, just like it.

For instance:

if something > 0:
    // do something
elif something < 0:
    // do something else
else:
    // looks like it is a zero

Just keep in mind that the indentation is crucial in GDScript.

1 Like

Thanks a lot, sounds so simple now!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.