0 votes

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 "restpoint = restnodes[0].global_position" part

It'd be a really great help thank you

in Engine by (17 points)

1 Answer

0 votes

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

by (188 points)

sorry for the reaaaally late reply

screenshot of the code

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

I think the problem is only that restnodes 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 restnodes 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.

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?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.