I have an autoloaded Singleton call ViewManager.
The ViewManager has one Table which has one Dealer which has one Deck and one Judge
I'm building a test frame for my game so it would be useful to access some of these major Nodes directly
I've tried a number of ways but I really thought this one would work.
I added these to my Singleton ViewManager (Just showing the code for the Deck node)
var Deck
func registerDeck(NodeType):
Deck = NodeType
print("registerDeck: " + str(Deck))
func getDeck():
print("Getting Deck " + str(Deck))
return Deck
References in scripts of other nodes to ViewManager.Deck or ViewManager.getDeck()
return a null. I have ensured the Deck node has been instantiated by including the registerDeck function which is called in the Deck _ready() script
_ready()
ViewManager.registerDeck(self)
The register functions work as the following printout shows:
registerDeck: [Node2D:2183]
registerJudge: [Node:2184]
registerDealer: [Node2D:2182]
registerTable: [Node2D:2161]
Yet, when I try to utilize the reference (in the Judge's testing method in this case) after the reports above (along with several intervening reports) have been made
print(str(ViewManager.getDeck()))
I get
Getting Deck [Object:null]
[Object:null]
The first report comes from the print statement in the ViewManager getDeck function
the second from the print statement in the Judge testing function
The Deck reference, which had been set, is now null.
This is baffling, since Deck is a variable that gets set once and then is only read. I had thought originally it might be due to threading but too much time intervenes between the reports for that to be likely.