Question about AutoLoad

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

I’m making an RPG where there are 8 characters. There’s a script for each one where all their data is handled (stats, level ups, skills, etc).

To access those stats more easily, I was thinking of making a “central hub” script which gets all the stats from the 8 different scripts, and then use that central hub script as a singleton.

My question is, if only the “central hub” script is in AutoLoad and not the other 8 scripts which have the actual variables, will other scenes be able to get those variables? And is this even a good idea, or should I just put all 8 scripts in AutoLoad?

Have you thought of using a Dictionary to hold all of the playable character (PC) data? With a single Dictionary, functions can be defined to get and set any data for the PCs. All of that can be placed in a script which can be called from each the PC’s scripts. Furthermore, each PC script can be a part of a base class, and that class can have functions which can be called on the Dictonary to get the relevant data without having to duplicate code (unless the scripts for the PCs use a base class already).

Ertain | 2021-07-26 18:23

Thanks a lot, I’ll try it out.

Rover | 2021-07-26 19:33

:bust_in_silhouette: Reply From: klaas

why not let the character register them selfs on the central hub on _ready.

#in the character
func _ready():

#in the central hub
var characters = {}

 func register_character( char ):
    characters[] = char #or any other key for easy access

Thanks a lot, I’ll try it out.

Rover | 2021-07-26 19:34