The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Probably a simple question here, is there a way to write a function in a global script that takes a node as a parameter that can be called by any specific nodes in a scene? I'm trying to make an inventory system that I can instance into every scene that will have functions that tell what to do with an object when clicked. ie "putInInventory", "sortInventory", "combineItems", etc. I'm guessing for the actual argument I could use the getnode but I'm not sure about the syntax for the parameter in the function definition. Would it be something like:
func moveItem(node):


in Engine by (34 points)

1 Answer

0 votes
Best answer

Yes, that's right.

Passing in a Node is exactly as passing any other type.

You just have to add the proper logic about which Node to pass, but that's up to you. :)

Not exactly pertaining to the question, but you would write node.set_pos(Vector2()) instead, at least for a Node2D.

by (182 points)
selected by

Thanks. Yeah vector2. I always realize that when I try to run it the first time. I never remember to do that before.

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.