![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | BOX_Milk |
hi, in general,
I’m making a crafting system in my game
and I’m implementing it through groups for an item
and I can’t create the item being created because the
script throws an error
script:
extends Area2D
@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:
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():
$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
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
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()
please help
you needed find what line give you your error in editor.
you cannot change anything in null instance
Moreus | 2023-03-09 18:15