The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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?

Godot version 3.3.2 stable
in Engine by (14 points)

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).

Thanks a lot, I'll try it out.

1 Answer

0 votes

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

#in the character
func _ready():
   central_hub.register_character(self)

#in the central hub
var characters = {}

 func register_character( char ):
    characters[char.name] = char #or any other key for easy access
by (4,088 points)

Thanks a lot, I'll try it out.

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.