In the "Your First Game," tutorial, the character disappears in the test.

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

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?

:bust_in_silhouette: Reply From: kidscancode

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”.

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?

jnatelowe | 2018-06-15 05:01

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

kidscancode | 2018-06-15 05:27

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.

jnatelowe | 2018-06-15 05:47

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

kidscancode | 2018-06-15 15:36

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

jnatelowe | 2018-06-15 17:26

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

kidscancode | 2018-06-15 17:27

Here it is:

1st Game Filezip

jnatelowe | 2018-06-16 06:13

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

kidscancode | 2018-06-16 18:20

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

jnatelowe | 2018-06-16 22:54