0 votes

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,

Godot version V 3.5
in Engine by (87 points)

2 Answers

+2 votes
Best answer

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)
by (6,932 points)
selected by
+2 votes

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

by (250 points)
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.