How should i write this?

I’m trying to write a code that if the player isn’t moving the “idleright” animation is played.

elseif action_id == hash("right") then
        self.input.x = 1
          if action.pressed then
            msg.post("#sprite", "play_animation", { id = hash("playerright") }) 
              else if action.released  
                 and self.moving = false then   --(Error) (What should be written in this line?)
               msg.post("#sprite", "play_animation", { id = hash("idleright") })
         end
     end

Have you seen my animation example?

An if-elseif-else in Lua looks like this:

if some_condition then
	print("something")
elseif some_other_condition then
	print("something else")
else
	print("everything else")
end

Note that there’s not space between else and if, so it’s elseif and not else if

2 Likes

= defines variables,
== is a comparative operator…
By tping self.moving = false you tried to make the script redefine the variable inside an if/else condition instead of checking for matching values.
And I’m pretty sure that’s all…
Hope I helped :slight_smile:

2 Likes

Also the else if/elseif thing…

1 Like

THIS Is exactly what i needed, thanks a ton.
It’s working perfectly now.

1 Like