Hi it tells me that line code 49 and 66 are wrong

it tells me that line code 49 and 66 are wrong
may you guys help me

extends CharacterBody2D

const speed = 100

var current_dir = “none”

func _physics_process(delta):
player_movement(delta)

func player_movement(delta):
if Input.is_action_pressed(“ui_right”):
current_dir = “right”
play_anim(1)
velocity.x = speed
velocity.y = 0
elif Input.is_action_pressed(“ui_left”):
current_dir = “left”
play_anim(1)
velocity.x = -speed
velocity.y = 0
elif Input.is_action_pressed(“ui_down”):
current_dir = “down”
play_anim(1)
velocity.y = speed
velocity.x = 0
elif Input.is_action_pressed(“ui_up”):
current_dir = “up”
play_anim(1)
velocity.y = -speed
velocity.x = 0
else:
play_anim(0)

	velocity.x = 0
	velocity.y = 0

	move_and_slide()

func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D

	if dir == "right":
		anim.flip_h = false 
		if movement == 1:
			anim.play ("side_walk")
	elif movement == 0:
		anim.play("side_idle)
	if dir ==

Please format your code by using three backticks, it’s impossible to read otherwise

1 Like

Hi!
When posting code, you should always post it like this:
grafik
That way, the code will look nice, like this:

thing.code()

Including the error message helps understand the issue you’re having.

Also it would be nice, if you could indicate, which lines are 49 and 66, so that we don’t need to count.

1 Like

i accidently forgot to add some the code in the text above

extends CharacterBody2D

const speed = 100

var current_dir = "none"

func _physics_process(delta):
	player_movement(delta)

func player_movement(delta):
	if Input.is_action_pressed("ui_right"):
		current_dir = "right"
		play_anim(1)
		velocity.x = speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_left"):
		current_dir = "left"
		play_anim(1)
		velocity.x = -speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_down"):
		current_dir = "down"
		play_anim(1)
		velocity.y = speed
		velocity.x = 0
	elif Input.is_action_pressed("ui_up"):
		current_dir = "up"
		play_anim(1)
		velocity.y = -speed
		velocity.x = 0
	else:
		play_anim(0)
	
		velocity.x = 0
		velocity.y = 0

		move_and_slide()
	
func play_anim(movement):
		var dir = current_dir
		var anim = $AnimatedSprite2D
		
		if dir == "right":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("side_walk")
		elif movement == 0:
			anim.play("side_idle)
		if dir == "left":
			anim.flip_h = true 
			if movement == 1:
				anim.play ("side_walk")
		elif movement == 0:
			anim.play("side_idle")
		if dir == "down":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("front_idle")
		elif movement == 0:
			anim.play("front_idle")
		if dir == "up":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("back_walk")
		elif movement == 0:
			anim.play("back_idle")```
1 Like

Your code has no valid indentation now

error at (49,14): expected closing “)” after call arguments

1 Like

Okay, this is better! Though please copy directly from the editor, that way, your code looks like this:

func shoot(target: Vector2):
	var bullet: RigidBody2D = bullet_scene.instantiate()

instead of this:

func shoot(target: Vector2):
var bullet: RigidBody2D = bullet_scene.instantiate()

Also, say which lines are causing problems specifically:

func shoot(target: Vector2):
	var bullet: RigidBody2D = bullet_scene.instantiate() # This doesnt work!

And also say what error you’re getting.

1 Like
...
func play_anim(movement):
		var dir = current_dir
		var anim = $AnimatedSprite2D
		
		if dir == "right":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("side_walk")
		elif movement == 0:
			anim.play("side_idle) # <- You forgot a "
...

Is maybe that the error? It should be

anim.play("side_idle")
1 Like

i accidently forgot to add some the code in the text above

extends CharacterBody2D

const speed = 100

var current_dir = "none"

func _physics_process(delta):
	player_movement(delta)

func player_movement(delta):
	if Input.is_action_pressed("ui_right"):
		current_dir = "right"
		play_anim(1)
		velocity.x = speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_left"):
		this is code 49: current_dir = "left"
		play_anim(1)
		velocity.x = -speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_down"):
		current_dir = "down"
		play_anim(1)
		velocity.y = speed
		velocity.x = 0
	elif Input.is_action_pressed("ui_up"):
		current_dir = "up"
		play_anim(1)
		velocity.y = -speed
		velocity.x = 0
	else:
		play_anim(0)
	
		velocity.x = 0
		velocity.y = 0

		move_and_slide()
	
func play_anim(movement):
		var dir = current_dir
		var anim = $AnimatedSprite2D
		
		if dir == "right":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("side_walk")
		elif movement == 0:
			anim.play("side_idle)
		if dir == "left":
			anim.flip_h = true 
			if movement == 1:
				anim.play ("side_walk")
		elif movement == 0:
			anim.play("side_idle")
		if dir == "down":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("front_idle")
		elif movement == 0:
			anim.play("front_idle")
		if dir == "up":
			anim.flip_h = false 
			if movement == 1:
				anim.play ("back_walk")
		elif movement == 0:
			this is code: 66: anim.play("back_idle")```
error at (49 , 14): expected closing after call arguments
error at 66: Unterminated string.

thank you it fixed the problem

2 Likes

Great, glad it works!
You can mark the comment that helped you in the end as the “Solution”. That way, the comment gets shown at the top so people don’t have to scroll all the way down.

before you go there a problem my game wont run

its telling me

1 Like

Now, that part is causing problems:

func play_anim(movement):
		var dir = current_dir
		var anim = $AnimatedSprite2D # <- This

The error means that you try to get a node, but the program can’t find it. Are you sure that the name is correct?

yes that is causing the problems
and I checked that’s the name

Screenshot 2024-03-11 215016
do they mean the player or the animtedsprite as a node

Is it a child of the node with the script?

It needs to be $CollisionShape2D/AnimatedSprite2D

that worked