![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | arthropod |
I’m a noob following a tutorial to make a resource-based inventory. The inventory screen populated fine when I assigned the relevant data to it directly, but once I assigned that data to a more relevant node, exported it, and tried to pass it over, everything broke. I just get a gray screen now.
I assume there has to be a problem referencing node paths but I don’t see it.
The last line here is getting flagged by the debugger:
@onready var clue_inv = $MarginContainer/ClueContainer/ClueInventory
func set_known_cluelist(known_clues: ClueListData) -> void:
clue_inv.set_known_clues(known_clues)
It shows "Invalid call. Nonexistent function “set_known_clues” in base “Nil”. It also shows the relevant variable (clue_inv) as “null”. That tracks with the error message.
…Except that I defined clue_inv right there. I dragged the path directly from the tree. I don’t know why it’s null.
In case it’s relevant, here’s the set_known_clues function:
func set_known_clues(known_clues: ClueListData) -> void:
populate_clue_list(known_clues.clue_slots)
populate_clue_list worked fine when I was manually assigning the test inventory data. I don’t think it’s the problem so I’m not including it here.
What am I not seeing?
As you’ve noted, the problem seems to be that your clue_inv
variable is null (so, not related to the set_known_clues()
function). How does set_known_cluelist()
get called (and from where)?
jgodfrey | 2023-07-07 15:53
set_known_cluelist() gets called in the ready function of the root node:
@onready var StoryScreen = $/root/Node2D/GameContainer/StoryScreen
@onready var MenuDisplay = $/root/Node2D/GameContainer/MenuContainer/MenuBounds/MenuMargin/TabController/MenuDisplay
func _ready():
MenuDisplay.set_known_cluelist(StoryScreen.known_clues)
“MenuDisplay” is the node to which the problem script is attached. “StoryScreen” is a node with a script that exports the variable known_clues, which holds the data I’m trying to access.
arthropod | 2023-07-07 16:41
If your script is on the root node, why do you use /root/Node2D/
in the path to get MenuDisplay
?
I’m asking this because if it actually happens to be a different branch of the tree, it would mean that MenuDisplay
is not a child of the node on which the script that calls set_known_cluelist
is. Which in turn means it could be an execution order issue since _ready
only guarantees that children are ready, not nodes of different branches.
(besides, it’s not a good idea to use absolute paths)
Zylann | 2023-07-07 17:37
First, I accidentally hit report instead of reply. I undid it but sorry if that did something.
This helped me figure it out, thank you so much!! I was accidentally trying to add set_known_cluelist to an autoload, not the root node script. I knew something was off there but it didn’t click until just now.
arthropod | 2023-07-07 19:43