tidying up my skill phases
november 12, 2020
#programming #skills
In Godot Engine, you can call methods from a parent class by prefixing it with a period (.). So to access the move()
method from a parent, call .move()
. This is called a super method.
Being called super doesn't mean there isn't a better way, though. I used to use super methods to build customs skills in blessfrey, but subfunctions is tidier.
(Just so you know, blessfrey's skills have a number of phases of effects that must happen in order: skill press > activation > initial phase > main phase > end phase > cooldown.)
the old way
Initially, I used super methods to give each phase custom effects and call the next phase. This was messy. If I ever redesigned the flow of the skill phases, I'd have to edit every single skill script. It also causes a lot of repetitive code in the individual skill scripts while the base script is tiny. The one-time script being the small one is no fair.
(You can see the old method's code on Pastebin.)
the new way
Instead, I can bring all the repetitive steps into the base class, sandwiching in a subfunction where the custom effects would take place. Now I only need to add what makes my skill unique inside the subfunction.
I named the subfunction after its main function and added an underscore to the front. So in the base script, I fit _functionality(user, action_target)
into functionality(user, action_target)
. Then the individual skill scripts only need the subfunction, none of the other repetitive code from before. The subfunction is empty in the base class and filled with unique code in the child classes. Since skills inherit, the unique _functionality
subfunction will be called automatically from the base script's functionality
.
(You can see the new method's code on Pastebin.)
problem solved!
The base script holds all the lengthy code in one place, while I only need to write the unique effects in all the hundreds of skill scripts. That saves me time making, refactoring, and maintaining skills. Yay.