Can you use a node as a func parameter?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thatsalottadimp
:warning: Old Version Published before Godot 3 was released.

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 get_node but I’m not sure about the syntax for the parameter in the function definition. Would it be something like:
func moveItem(node):


:bust_in_silhouette: Reply From: RandomShaper

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. :slight_smile:

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

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

thatsalottadimp | 2017-07-26 22:35