New to Godot, not to programming. I am using a dictionary to contain spawning information. As i have been expanding the size of the game, the dictionary has gotten larger. It has been working just fine but I wanted to move it to its own Node for readability.
I have copied the whole dictionary from one Node to another. Now when loading the dictionary it always causes the following error on the line indicated below:
Invalid get index ‘position’ (on base: ‘null instance’).
I have found other people getting this error and I understand that it means i am trying to reference something that does not exist. However, the code is copied from one Node to another. The only change that was make was the dictionary is now named differently.
Ex:
Original code:
var Levels = {}
Levels[“Level_1”] = { … Works fine and loads as expected
New code:
var lvl = {}
lvl[“Level_1”] = { … always fails with the above error
The new Node is a child of the original, and the original calls a function in the child in the same way it called a function in itself.
Ex:
Original Code:
This_Level = GetLevel()
New Code:
This_level = $lvl.GetLevel()
Really scratching my head as to what the difference between the two could be. Any help would be greatly appreciated.
Thank you for the tip on dragging a dropping the node names. That is a nice feature i was unaware of. But unfortunately that is not my issue. The Node path is correct.
no i meant if you try to get the level at _ready function, because it may be that your node read too fast before the node of lvl is ready/existed in the scene, hence why the error said it’s null
try add
Invalid get index ‘position’ (on base: ‘null instance’)
This isn’t a dictionary access error.
This error is telling you that you tried to set the position property on something that is null.
You need to show the line the error is on.
I tried defining the variable in line in the “BuildLevels” function, no change
I have tried constructing the dictionary at the time of defining the variable; both inside and outside of the “BuildLevels” function, in this instance the lvl dictionary is “Null” in stead of empty
As Tayacan says it is a problem with $S1, $S4, and/or $S5.
Before accessing lvl[...], try: printt($S1, $S4, $S5)
If any of those print null, then you need to figure out what is going on with those nodes.
More than likely the code you show is from the other original initiation that you did, and now that the code is in a different node, S1, S4, S5 are at a different path structure.
The issue was that the markers, that were holding the position data, were part of the Parent Node (Original location) and not the Child node (New Location).
I was focusing on the dictionary being empty. I was thinking that it would have added some of the sub-dictionaries (Like “Wave_1” or “Ripple_1” before any error would have triggered.
Thank everyone for their help, I very much appreciated it!