0 votes

I've only recently started Godot and it's a bit hard to find the information I'm looking for, I would appreciate any help!

I've been using preload to access other scripts that are not within the tree the current script is in, except sometimes those scripts also need to preload other scripts that aren't in the tree either.

Basically:
A) print B.x -> can access B
B) x = var C.y -> can't access C, creates error
C) var y

It doesn't break if I, say, preload script C directly inside of B's function as opposed to just writing it out at the top, but it sounds like horrible spaghetti code to do that for every single function that I theoretically need access to.

I'm using the GDQuest Turn Based RPG open source as reference and it doesn't appear to run into this problem at all, but just looking at the code I can't tell how it's being bypassing it. Also I feel like all this preloading stuff is inefficient too, but I don't know any workarounds.

Godot version 3.3.2
in Engine by (12 points)

Do you know about the concepts of object-oriented programming? Have you looking into using inheritance for the code?

Besides the fact you could use some kind of global script (Singleton), it could help if you try to reproduce your problem in a smaller scope, so you can also show us concrete code. Without it is extremely hard to tell what your problem is. Especially if you recently started Godot, you should get used to always present some real gd-script code.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.