invalid get index "0" on base: array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Numshv

So i encountered an error that says “invalid get index “0” on base: array” but i don’t really know how to fix it cuz like tbh i don’t see the issue here. I’ve tried to change the line a couple bit and play around with it and it enter image description herestill gives the same error or made a new error.

Here’s the line of code that has the problem

The error is in the “rest_point = rest_nodes[0].global_position” part

It’d be a really great help thank you

:bust_in_silhouette: Reply From: IvanVoirol

Could you post the rest of the script, so we could see what restnodes is?

sorry for the reaaaally late reply

screenshot of the code

that’s the whole script btw!
thank you very much

Numshv | 2022-07-13 00:28

I think the problem is only that rest_nodes isn’t properly loaded when called. It’s either null or empty, which means there are no nodes in the group "nodes", in which case you should add a if statement to check if rest_nodes contains elements :

if rest_nodes.size() < 0):

Are you trying to get the position of an object? There is maybe an easier way to do so that doesn’t require groups. If you say more about it, I could try to help you find a better replacement.

IvanVoirol | 2022-07-17 09:09

Thank you for the answer again!

Yes I’m working on a drag and drop mechanics and this code is to make the object to automatically adjust its position so that it drops right into the center of the drop area.

Do you know any other way to do it?

Numshv | 2022-07-19 16:03