Poblem whit thise code

Godot Version

Latest (steam)

Question

I dont know how to resolve this, any help?

First Code (controler for the player):
extends CharacterBody2D

const SPEED = 200.0
const JUMP_VELOCITY = -400.0

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

@onready var _animated_sprite = $AnimatedSprite2D
@onready var bullet_scene = preload(“res://Esenas/Bullet.tscn”)
@onready var hit_area = $HitArea

var can_double_jump = true

func _ready():
hit_area.connect(“body_entered”, self, “_on_HitArea_body_entered”)

func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta

handle_movement()

move_and_slide(velocity, Vector2.UP)

func handle_movement():
if is_on_floor():
if Input.is_action_just_pressed(“ui_accept”):
velocity.y = JUMP_VELOCITY
_animated_sprite.play(“salto”)
can_double_jump = true
elif can_double_jump and Input.is_action_just_pressed(“ui_accept”):
velocity.y = JUMP_VELOCITY
_animated_sprite.play(“doble”)
can_double_jump = false

    var direction = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    velocity.x = direction * SPEED

    if direction > 0:
        _animated_sprite.play("correr")
    elif direction < 0:
        _animated_sprite.play("correr_detras")
    else:
        _animated_sprite.play("quieto")

func _stop_animation_after_delay(delay):
await get_tree().create_timer(1.0).timeout
_animated_sprite.stop()

func _shoot_bullet():
var bullet_instance = bullet_scene.instance()
get_parent().add_child(bullet_instance)
bullet_instance.global_position = global_position
var direction = (get_global_mouse_position() - global_position).normalized()
bullet_instance.set_velocity(direction * SPEED) # Assuming Bullet has a ‘set_velocity’ method

func _on_HitArea_body_entered(body):
print("Hit by: ", body)
# Implement collision handling logic here
second (dessapear whit a bullet):
extends Node2D

var velocity = Vector2()

func _physics_process(delta):
position += velocity * delta

func set_velocity(v):
velocity = v

What is the problem? And write the codes in code format like this:

print("Hello World!")
# I used ``` codes ``` for this code box
2 Likes

ok the poblem is that i dont know what to do to this errors res://Esenas/Area2D.gd:4 - Parse Error: Member “body_entered” redefined (original in native class ‘Area2D’)
res://Esenas/Area2D.gd:8 - Parse Error: Invalid argument for “connect()” function: argument 2 should be “Callable” but is “res://Esenas/Area2D.gd”.
res://Esenas/Area2D.gd:8 - Parse Error: Cannot pass a value of type “String” as “int”.
res://Esenas/Area2D.gd:8 - Parse Error: Invalid argument for “connect()” function: argument 3 should be “int” but is “String”.
modules/gdscript/gdscript.cpp:2726 - Failed to load script “res://Esenas/Area2D.gd” with error “Parse error”. (User)
res://Esenas/Player.gd:15 - Parse Error: Invalid argument for “connect()” function: argument 2 should be “Callable” but is “res://Esenas/Player.gd”.
res://Esenas/Player.gd:15 - Parse Error: Cannot pass a value of type “String” as “int”.
res://Esenas/Player.gd:15 - Parse Error: Invalid argument for “connect()” function: argument 3 should be “int” but is “String”.
res://Esenas/Player.gd:23 - Parse Error: Too many arguments for “move_and_slide()” call. Expected at most 0 but received 2.
modules/gdscript/gdscript.cpp:2726 - Failed to load script “res://Esenas/Player.gd” with error “Parse error”. (User)
image

  1. You redefine same function in same script
  2. You used wrong way to connect a signal
  3. You insert wrong type, it showing that you need to give int but you give it string, you can to like int(your_value)
  4. move_and_slide not need anything
    … show me the codes in code format again

Your codes is fully wrong, looks like you are porting from Godot 3 to Godot 4 or new to game dev

ok i gonna do the back up to my code

1 Like

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