#Dictionary tag bugs

1 messages · Page 1 of 1 (latest)

lost geyser
#

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.

#

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.

door.gd


@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)

NavCon.gd


@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, "")
knotty lily
#

If you look at the node instance with the exported dict in the inspector, what data does it contain?

lost geyser
knotty lily
#

And the value after Error: Invalid level tag provided: matches the key string exactly? No trailing spaces etc?

lost geyser
#

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

knotty lily
#

What does this print? print_debug("NavCon scenes dictionary:", scenes)

lost geyser
#

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

knotty lily
#

Hmm, autoloads can be a bit tricky

lost geyser
# knotty lily 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.

knotty lily
#

Do you only call catalog() from _process(), or somewhere else too?

lost geyser
#

ya that's the only place

knotty lily
#

Are you using NavCon.gd directly as an autoload?

lost geyser
knotty lily
#

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..

lost geyser
#

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

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?

lost geyser
pearl frost
#

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.

knotty lily
#

I think they meant that they put the script on a node and replaced the old auto-load (script only) with that

pearl frost
#

I do not think it would really help, but if it works, it works.

lost geyser
knotty lily
#

Well, in that case you definitely shouldn't have both.

lost geyser
pearl frost
#

I mean, having an autoload has no bearing on being able to access a local node.
Thry do not shre the same dictionary even

lost geyser
pearl frost
#

I do not think you are understanding how autoloads work

lost geyser
knotty lily
# lost geyser I didn't know any other way to access the dictionary out side of that.

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.

lost geyser