Godot Version
4.3
Question
Pt-br
Olá, estou a algum tempo tentando chamar uma função de um script para outro, porem ele diz que o node não existe, já tentei usar tanto a função signal quanto a mais simples com só a get_node.
Eng
Hello, I’ve been trying to call a function from one script to another for some time, but it says that the node doesn’t exist. I’ve tried using both the signal function and the simpler one with just get_node.
Scripts:
Coin:
extends StaticBody2D
@onready var cont = get_node(“player”)
func _on_area_2d_body_entered(body: Node2D) → void:
if body.name == "Player":
print("pegou")
cont.cont_moedas = +1
queue_free()
if has_node("player"): #Debug
print("Nó encontrado!")
else:
print("Nó não encontrado!")
pass # Replace with function body.
Player:
extends CharacterBody2D
var SPEED = 150.0
const JUMP_VELOCITY = -400.0
var cont_moedas = 0
@onready var _animated_sprite = $AnimatedSprite2D
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
if Input.is_action_just_pressed("B_correr"): #função experimental
velocity.x = direction * 5000
else:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if Input.is_action_pressed("ui_left"):
_animated_sprite.play("AA_esquerda")
if Input.is_action_pressed("ui_right"):
_animated_sprite.play("AA_direita")
if direction == 0:
_animated_sprite.stop()
move_and_slide()