Packedscene won't register as packedscene when trying to check for new dictionary key:
I’m trying to make a dictionary that holds different packedscenes of bullets I’ve made for a main project I’m working on.
Issue:
the problem is that when I’m using the built in function I made (add_to_bullet_dictionary(key_name:String, _preload:PackedScene))
for some reason the packedscene I’m trying to add doesn’t register as one in the code, but shows in a error print i made as a packed scene:
Code below:
extends Node
class_name bullet_container
var global_dict: Dictionary = {}
extends CharacterBody2D
class_name bullet_logic
@export_group("physics")
@export var speed:int
@export var damage_over_time:int
@export var raw_damage: int
func _physics_process(_delta: float) -> void:
move_and_slide()
func add_to_bullet_dictionary(key_name:String, _preload:PackedScene):
if _preload != PackedScene:
push_error("preload is not a packscene but is: ", _preload)
if _preload == null:
push_error("_preload is null")
# adds key to dictionary when _preload is a packscene and key_name is not found in dict:
if not BulleftDict.global_dict.has(key_name) and _preload == PackedScene:
BulleftDict[key_name] = _preload
extends bullet_logic
var bullet_name = "purple bullet"
@onready var _preload:PackedScene
func _ready() -> void:
_preload = preload("res://Scene's/Bullets/purple_bullet.tscn")
add_to_bullet_dictionary(bullet_name, _preload)
print(BulleftDict.global_dict)
func _on_area_2d_mouse_entered() -> void:
queue_free()
print("mouse is in box")
So I tweaked the code and now I’m getting an old error that pop-up before I started checking to see if the node was a packed scene. And that’s the invalid assignment to property error.
I know that it occurs when the type you’re trying to put through is wrong, but everything points to the item still being a packedscene so it’s somewhat confusing.
Code below:
extends CharacterBody2D
class_name bullet_logic
@export_group("physics")
@export var speed:int
@export var damage_over_time:int
@export var raw_damage: int
func _physics_process(_delta: float) -> void:
move_and_slide()
func add_to_bullet_dictionary(key_name:String, _preload:PackedScene):
if _preload is not PackedScene:
push_error("preload is not a packscene but is: ", _preload)
if _preload == null:
push_error("_preload is null")
if not BulleftDict.global_dict.has(key_name) and _preload is PackedScene:
BulleftDict[key_name] = _preload
extends bullet_logic
var bullet_name = "purple bullet"
@onready var _preload:PackedScene
func _ready() -> void:
_preload = load("res://Scene's/Bullets/purple_bullet.tscn")
var _load = _preload.instantiate()
add_to_bullet_dictionary(bullet_name, _preload)
print(BulleftDict.global_dict)
func _on_area_2d_mouse_entered() -> void:
queue_free()
print("mouse is in box")