Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DaddyMonster |
I’ve got an annoying script error popping up. I’ve got a singleton called Global with an empty array:
var planets = []
From another script I’m appending several object elements, eg:
Global.planets.append($Player)
When I simply print the array with:
print(Global.planets)
It works but, bizarrely, it throws: “SCRIPT ERROR: _physics_process: Invalid get index ‘planets’ (on base: ‘Node (Global.gd)’).” as if I’m calling an index outside the range of elements. But all I’m doing is printing the whole array… The size() method tells me I have 3 elements so I’m not out of range, the objects are in the scene.
Not only that but it unexpectedly returns nested arrays:
[[KinematicBody:1423], [KinematicBody:1304], [KinematicBody:1396]] instead of the expected [KinematicBody:1423, KinematicBody:1304, KinematicBody:1396].
The same thing happens when I loop through them:
for obj_1 in Global.planets:
“SCRIPT ERROR: _physics_process: Invalid get index ‘planets’ (on base: ‘Node (Global.gd)’).”
It was working fine before so I’ve no idea what I’ve done…
Any ideas?
It is not a nested array, when you print a node to the console, you will get its ID in square brackets.
yanb | 2020-11-03 15:58
Is the project available somewhere to look at?
jgodfrey | 2020-11-03 18:24
Thanks so much, I had no idea the equivalent of the python dunder method __repr__
returned objs in square brackets to the console in gdscript. What a terrible language design decision, it’s as if it were designed to confuse… Good to know though. Thanks again.
Anyway, the warning goes away when I remove tool
in the script, so I’m going to mark this as resolved. Most likely I was just missing a ‘tool’ in an associated script.
DaddyMonster | 2020-11-04 10:38