make a utility script

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

Hi everyone,
I would like to make a script with a lot of small useful functions but which have their place everywhere in the scripts. how would you do it? Should it extend a class? How to call it in a script?

good evening,

:bust_in_silhouette: Reply From: Mario

This sounds like something you’d typically put in a global/autoload.

:bust_in_silhouette: Reply From: Wakatta

Utility script

class_name Utility extends Reference

func electrical():
    pass

func water(speed):
    pass

Player Script

extends Node

func _ready():
    var utility = Utility.new()
    utility.electrical()

Some other script

extends Control

onready var utility = Utility.new()

func _ready():
    utility.electrical()

func _process(delta):
    utility.water(delta)