If you had the patience to watch my bungling 24 minute Construct 2 first attempt at a "Tutorial," you'll know I love using groups.
I love groups and I want to marry them.
Here's my event sheet for the main game layout in Captain Zero (where all the real action happens) so far --that's right I'm letting everyone see my source code!:
See it's all there! Grouping your code not only makes it really easy to read and isolate different parts, but the ability to turn off or on a group makes them act like sort of asynchronous methods --which are sometimes more clumsy to make in traditional languages.
It's a method that keeps happening until you tell it to stop instead of terminating at the end of it... unless you tell it to stop at the end of it --which you can in which case its just like a method.
Here... I'll open up the "Star" Group and you can see the events in it...
What the heck? More groups! Because all the effect events associated with the star are in the Star group, I can turn off that whole group if the star is behind something or off the screen and turn it back on when it's back in view. When it's all in one place you can keep it under control. This is the heart of what computer science calls the rule of "Encapsulation."
People often include the concept of "information hiding" (i.e. public and private variables etc.) when talking about encapsulation, but that's not what it's really about. restriction does help enforce encapsulation but really all encapsulation is, is keeping data and functionality bundled together and all in one spot for one thing.
I don't, for example spread events that affect the star all over the event sheets or have other events affect the star except in a very controlled way.
They can either turn the whole thing off or whole thing on. No where in the fighter events for example, can you change the disposition of the star's lense flare... because the star's lense flare is the star's job and the section of code dedicated to the star should handle it. And that's the real spirit of encapsulation.
Turns out the spirit of encapsulation is kinda creepy at first, but you get used to it.
...but then the Spirit of Abstraction comes in and moans forebodingly "...but what if you waaant other things besides the star to have lense flair?"
ReplyDeleteI dont. Shut up Spirit of Abstraction! Vex me not this night!