![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | BOX_Milk |
Hello
I have a problem
when creating an item in the conditions, I get errors
but when code snippets are removed, everything works without errors
here is the error in the debuggers:
- loading: unable to load dependency: res://prefab/item.res.
- __load: Failed to load resource: res://scene/world.scene. Verify that the resources have been imported by opening the project in the editor at least once.
- set_path: Another resource is loaded from the path ‘res://scene/world.scn’ (possibly cycling the resource).
- item.gd:47 @ _process(): Condition “nc == 0” is true. Return: nullptr
- item.gd:48 @ _process(): parameter “p_child” is null.
- Invalid specified index “position” (based on: “null instance”) with a value of type “Vector2”.
code that causes errors:
extends Area2D
# [ НАСТРОЙКА ]
# name
@export var key = ""
@export_multiline var decs = ""
@onready var player = get_parent().get_node("player/inventory") # ссылка на игрока
@onready var world = get_parent().get_parent().get_node("world") # ссылка на мир
# переменная
var enter = false # соприкосновение с игроком
var pickup = false # в инвентаре
var craft_id = 0 # крафт ?
var kd = 1.5 # кд начало
var kd_ = 0 # кд использовние
func _ready():
$name.text = key
$name.hide()
$anim.play("ilde")
func _process(_delta):
# кд система
kd_ -= 0.01
# если мы вошли в колизию
if enter == true:
$name.show() # показ текста
if Input.is_action_just_pressed("use") and player.get_child_count() < 1: # если мы нажали "E"
pickup = true # включение для того что-бы добавить
add() # подбор
if Input.is_action_just_pressed("drop") and pickup == true:
drop()
# использование
if pickup == true:
use() # использование
# крафт
if enter == true and player.get_child_count() == 0:
if craft_id == 1:
if Input.is_action_just_pressed("craft"):
var spawn = preload("res://scene/world.scn").instantiate()
get_parent().add_child(spawn)
spawn.position = player.global_position
$name.text = "Q"
$body.shape.radius = 8
else:
$name.text = key
$body.shape.radius = 5
# использование
func use():
# default
$name.hide() # скрытие надписи
look_at(get_global_mouse_position()) # поворачиваеи на курсор
# система поворота
if get_global_mouse_position().x < global_position.x:
self.scale.y = -1
else:
self.scale.y = 1
if Input.is_action_pressed("LMB") and kd_ <= 0:
$anim.play("use")
kd_ = kd
# custom
# подбор
func add():
get_parent().remove_child(self) # удаления из прена нас
player.add_child(self) # добовляем себя дочерний узел игроку
self.position = Vector2.ZERO # устанавливаем позицию
$art.offset.x = 2 # отдаляем от тела
$name.hide() # скрытие надписи
# дроп
func drop():
player.remove_child(self) # удаляем себя из игрока
world.add_child(self) # миру добовляем себя
rotation_degrees = 0 # поворот = 0
self.position = player.global_position # выбрасываем под игрока
self.scale.y = 1 # возращяем поворот
$art.offset.x = 0 # стандарт
pickup = false # выключаем
$name.hide() # скрытие надписи
func _on_area_entered(area):
if area.is_in_group("test"):
craft_id = 1
func _on_area_exited(area):
if area.is_in_group("test"):
craft_id = 0
func _on_body_entered(body):
if body.is_in_group("player"):
enter = true
func _on_body_exited(body):
if body.is_in_group("player"):
enter = false
$name.hide() # скрытие надписи
I have attached a video where I show the errors and how they are supposed to be:
thank you in advance
As humans, we have a responsibility to protect and care for animals. It’s not just about compassion, but also about ensuring that the environment we share with them is safe and healthy. Please checkout: Animal Welfare
kitticpet | 2023-03-11 07:11