Smart way to include other script files + how does preload/load work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mantas Aramavičius
:warning: Old Version Published before Godot 3 was released.


So I’ve been working/trying/learning godot for a week now and i noticed that it lacks “actions” (for example fade out action. Set a timer, and over that timer the fadeout action would be performed). I’ve tried replacing it by using _fixed_process or _process to simulate timers by using delta, but that’s not really clean. Also used the Timer node, but having multiple of those auto cleaning becomes tricky and it isn’t a clean way to do it either.

So I got an idea to make some specific class that would have actions to work on and auto clean after. I have experience writing this kind of thing so writing it is no problem to me. My problem is:

  1. Is there a smart way to include other script files?

  2. Is there a way to make script files part of the core? (Kind of like everything else godot offers) Or do i have to work on the cpp side and recompile the entire engine?

  3. How does load and preload work - exactly. I know load loads when you ask it to, and preload loads before the _ready() is called. But i’m curious when the preload starts? if i have a node that isn’t yet added and it has a script that preloads, does the preload only happen when i add the node? If i have multiple nodes that preload the same file, does the same file preload multiple times? How stupid would it be to just use preload for some core helper functions? (Like actions i mentioned)

This isn’t an answer to your question, so I’ll just add it as a comment. In order to fade out something you can simply use an animation.
If you must do it in code you can use the Tween node to accomplish the same thing. See here: Tween — Godot Engine (stable) documentation in English
In the description ( Tween — Godot Engine (stable) documentation in English) there’s even an example that uses the method you are probably most interested in.

Warlaan | 2016-11-13 00:17

Reddit - Dive into anything

atze | 2016-11-13 09:38

:bust_in_silhouette: Reply From: eons

1- Don’t know what “smart way” means.
2- You can add your own module if want something extra as part of the core and compile the engine with it (c++). There’s the option of plugins/tools if you want to make a custom node (not part of the engine).
3- Preload happens at parse time as doc says

You can make those “actions” with animations, example:

  • create an opacity animation that affects the parent.

  • save it on disk as resource.

  • load it on the animationplayer of every node you need that animation on parent _ready.

  • play it when needed.

Yeah, I wouldn’t want to be using it the dumb way. XD

avencherus | 2016-11-13 18:35