So I'm having issues with Dictionary I added a @export to my NavCon script and it holds all the scenes witch now is returning a Invalid Tag debug error in my door script and I'm going nuts trying to figure out how to get it to work the way I had it before where the tags would tell the scene manager to go to a set scene by the scenes tag.
#Dictionary tag bugs
1 messages · Page 1 of 1 (latest)
Provide Bellow is my door.gd and NavCon.gd script if you have questions please ask, If I have this in the wrong channel please let me know.
@export var trans_to: String = "" # Level tag to determine the scene
@export var goto_Scene: String = "" # This will now be set dynamically
@export var target: String = ""
@export var door: bool = false
var can_Knock: bool = false
var level_Load: String = "" # Keep level_Load as the tag
var trans_scene: bool = false
func _process(_delta):
change_scene()
door_Knock()
catalog()
func _on_body_entered(body):
if body.has_method("player") && door == false:
print_debug("Player entered door")
trans_scene = true
elif body.has_method("player") && door == true:
can_Knock = true
func change_scene():
if trans_scene == true and goto_Scene != "": # Ensure goto_Scene is valid
Global.stage_Manager.change_2d_scene(level_Load, goto_Scene, target)
Global.fin_change()
trans_scene = false
print_debug("Scene changed to: ", goto_Scene)
func door_Knock():
if can_Knock == true && Input.is_action_just_pressed("Action_Key"):
trans_scene = true
func catalog():
level_Load = trans_to # Use trans_to as the tag for level_Load
goto_Scene = NavCon.scenes.get(trans_to, "") # Dynamically set goto_Scene based on level_Load
if goto_Scene == "":
print_debug("Error: Invalid level tag provided: ", level_Load)
else:
print_debug("Scene found:", goto_Scene)
@export var scenes: Dictionary = {}
func _ready():
print_debug("NavCon scenes dictionary:", scenes)
func get_scene_by_tag(level_tags: String) -> String:
return scenes.get(level_tags, "")
If you look at the node instance with the exported dict in the inspector, what data does it contain?
2 strings one marked Key and the other marked Value the key is where I'm putting the Tag while the Value is the path to the scene I want to go to.
And the value after Error: Invalid level tag provided: matches the key string exactly? No trailing spaces etc?
At: res://Scripts/door.gd:39:catalog()```
This is what I get every run.
It's just one of the lines but it goes through all my door of each tag there tied to since I'm on my main test room it doesn't bring up the feild tag
What does this print? print_debug("NavCon scenes dictionary:", scenes)
This one fires off twice honestly I just list what's in the dictionary ```NavCon scenes dictionary:{ "cliff": "res://Scenes/test_cliff.tscn", "feild": "res://Scenes/test_room.tscn", "field2": "res://Scenes/Rest.tscn", "house": "res://Scenes/Test_Home.tscn", "house2": "res://Scenes/Test_Home2.tscn" }
At: res://Scripts/AutoLoad Scripts/NavCon.gd:6:_ready()
The first time is the auto load and it's just blank
Hmm, autoloads can be a bit tricky
Ya I kinda figured the person who pointed me to this stuff was recommending I make some kinda array from a file that holds all my scenes. So I tried custom resource and it just kinda tanked so I did this.
Do you only call catalog() from _process(), or somewhere else too?
ya that's the only place
That was what it was originally I had what I'm doing with the dictionary now all written out and it work fine but I was going to have a tun of scenes since I'm doing a rpg kinda deal
Try creating a scene with just a Node that has the NavCon.gd script attached, then then use the scene as an autoload instead of the script. I saw somewhere that this might make a difference..
Well it's what I'm trying to figure out. Since the OG script I have made things a bit more stream line
This is what my NavCon script looked like before this dictionary thing ```class_name Nav extends Node
const feild = "res://Scenes/test_room.tscn"
const cliff = "res://Scenes/test_cliff.tscn"
const house = "res://Scenes/Test_Home.tscn"
const house2 = "res://Scenes/Test_Home2.tscn"
const feild2 = "res://Scenes/Rest.tscn"
func get_scene_by_tag(level_tags: String) -> String:
match level_tags:
"feild":
return feild
"feild2":
return feild2
"cliff":
return cliff
"house":
return house
"house2":
return house2
_:
return "" # Return an empty string for invalid tags```
and the doors ```class_name Door extends Area2D
@export var trans_to: String = "" # Level tag to determine the scene
@export var goto_Scene: String = "" # This will now be set dynamically
@export var target: String = ""
@export var door: bool = false
var can_Knock: bool = false
var level_Load: String = "" # Keep level_Load as the tag
var trans_scene: bool = false
func _process(_delta):
change_scene()
door_Knock()
catalog()
func _on_body_entered(body):
if body.has_method("player") && door == false:
print_debug("Player entered door")
trans_scene = true
elif body.has_method("player") && door == true:
can_Knock = true
func change_scene():
if trans_scene == true and goto_Scene != "": # Ensure goto_Scene is valid
Global.stage_Manager.change_2d_scene(level_Load, goto_Scene, target)
Global.fin_change()
trans_scene = false
print_debug("Scene changed to: ", goto_Scene)
func door_Knock():
if can_Knock == true && Input.is_action_just_pressed("Action_Key"):
trans_scene = true
func catalog():
level_Load = trans_to # Use trans_to as the tag for level_Load
goto_Scene = NavCon.get_scene_by_tag(trans_to) # Dynamically set goto_Scene based on level_Load
if goto_Scene == "":
print_debug("Error:
Invalid level tag provided: ", level_Load)```
And this worked @knotty lily
I created a small test project, and the autoload's _ready() function only runs once, with the correct dict values
Did you try changing the autoload so that it is a scene (Node) and not only the script?
Oh the reason it fire twice was in order to use the @export I had to put the auto load script on a node
You shouldn't.
Godot will automatically create a node when you make a script an autoload. So this would net you 2 nodes
So either remove the autoload or leave only the autoload.
I think they meant that they put the script on a node and replaced the old auto-load (script only) with that
I do not think it would really help, but if it works, it works.
No.....the autoscript was still a thing but the node version was made so I could access the dictionary and mod it through a node instead of hard wiring via code.
Well, in that case you definitely shouldn't have both.
I didn't know any other way to access the dictionary out side of that.
I mean, having an autoload has no bearing on being able to access a local node.
Thry do not shre the same dictionary even
well I made the local node to house the script that is Autoloaded by defualt because I didn't know how to access and mod a @export dictonary
I do not think you are understanding how autoloads work
bits and peaces honestly right now I had to revert back a version to get the doors to work again and now trying to do the same dictionary thing again
Perhaps I'm misunderstanding what you're doing, but if you have a script x.gd attatched to a node which you save as x.tscn and you make that node/scene an autoload then you'll have access to all the functions/variables in the script through that node.
If you make the x.gd script an autoload, you will also get access to its functions, but it seems like exports work differently, I guess because they'll be associated to this node that Godot creates automatically for the script.
But there is really no point in doing both afaik.
I mean your not wrong I just don't know what I'm really doing with Dictionary really