0 votes

I'm working through the "Your First Game," (Or "Dodge the Creeps," here) tutorial. It seems to be working fine when I test it, until I get the part where the script is supposed to flip the character sprite horizontally and vertically to follow left and right and up and down movement. Then when I run the test the character is initially present in the scene, but disappears when i push any of the arrow keys to move it. If I delete that section of code, it works fine again (except of course the character is back to facing only one direction all the time).

Here's the section of code that's not working:

if velocity.x != 0:
    $AnimatedSprite.animation = "right"
    $AnimatedSprite.flip_v = "false"
    $AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
    $AnimatedSprite.animation = "up"
    $AnimatedSprite.flip_v = velocity.y > 0

Actually, I just tested it again and now the scene window freezes and stop responding. There's a warning in the debugger saying "Invalid set index 'flip_v' (on base: 'AnimatedSprite') with value of type 'String'. I don't know what this means or how to fix it. Can anyone help me?

asked Jun 14 in Engine by jnatelowe (12 points)

1 Answer

+1 vote

This is the problem:

$AnimatedSprite.flip_v = "false"

It's telling you you can't use a string for the value of flip_v because it needs to be a boolean. Remove the quotes around "false".

answered Jun 14 by kidscancode (5,720 points)

Ok that fixed the "Invalid set index," problem, but now it's back to just disappearing when I try to move the character in the scene. Code now looks like this:

if velocity.x != 0:
    $AnimatedSprite.animation = "right"
    $AnimatedSprite.flip_v = false
    $AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
    $AnimatedSprite.animation = "up"
    $AnimatedSprite.flip_v = velocity.y > 0

If I delete this part of the code, it works fine, except that the character sprite always stays facing the same direction. Is there anything else I'm doing wrong?

Look in the "Debugger" tab (at the bottom). Are you sure you're not getting an error there?

I checked, and the only thing it says is "Child Process Connected," In green text. When I had errors before the debugger message would be in red.

I suspect the problem isn't with the code, but with the animated sprite. Can you zip your project and share it?

Yeah, I can do that later tonight. Is there a way to attach it to this message?

You can link it, but you'll have to upload it somewhere (Google drive, etc).

Here it is:

1st Game Filezip

Your AnimatedSprite animations are named "Up" and "Right", but in your code you wrote "up" and "right". The names need to match.

Ahh, man, thanks so much. Obviously I'm new to coding. Thank you for taking the time to help me.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.