Add behavier to the base node

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

Hi
I am trying to add an array to the base node called tags so all nodes i my tree will have a tags array. is there anyway to overide the code for the base node to do that or are there other better methods.
Thanks in advance

:bust_in_silhouette: Reply From: Sween123

Definitly yes.
That is what called “extends”. (However it’s extending a script instead of a node, but scripts are attached to nodes)
So for your base node, you have a script, let’s say it’s BASE_NODE.gd. Inside this you have different variables, for other nodes to inherit it’s properties, in their scripts, you use extends "res://YOURPATH..../BASE_NODE.gd"

There are also alternative ways. If you want this tags array to be like some kind of global variable, in all other different nodes, you simply add a function like:

function get_tags():
  return get_node("/root/BASE_NODE").get("tags")

So what is returned will be exactly the variable tags from the BASE_NODE. If something inside this array changed, they changed together.