
Using "global names"
No enums? No problem.
String literals? Yuck. More typo protection, better autocompletes, enhanced usage lookups? Yes please!
OG Construct developer Salman Shurie referred to the engine's event system as "super intellisense" a couple of times - turns out the phrase was coined by @wtfmig. Nevertheless, I think it's on point.
When you're using the event system (and no JS/TS code), you can't mistype names of variables, constants, behaviours, objects, families or functions, because the editor simply won't let you. You can also rename any of these without worrying about breaking code, Construct automatically updates all references to reflect the name change (again, as long as they are not mentioned in JS/TS code). If you're using the paid version, the editor can also find all usages of variables, constants, objects and family members. It's an amazing tool and I use it countless times during development.
There are some things you can still mistype, since they are not structured as identifiers, but strings. Layer names, animation names, effect names, various tags (for tweens, timers, sounds, et cetera) can be entered as string literals. Construct tries to suggest them, but you can still make a typo and you don't get usage finding. And if you decide to rename a layer, animation, effect or any sort of tag, you'll have to manually search for it and change it manually by hand which is tedious and error prone.
Rather than doing that, you can create global constants (which are identifiers) and use them instead of string literals. This way you get typo protection, usage lookups and renaming things is a lot easier once you resist the urge to use string literals in those cases. Granted, there's an extra step (creating a global constant), but I think it's worth the effort.
In my projects I put all "global name" constants in an event sheet called vNames
. Since it only contains variables, it's automatically "included" in all events sheets, so you don't have to worry about importing it. (By the way the same goes for functions and custom actions too; only sheets containing events have to be included to run.)
You can also apply a naming convention on the global "name" constants to signify their "kind", eg:
LAYER_Main = "Main"
(value matches the layer name)TIMER_Invincibility = "Invincibility"
(timer tag)TWEEN_FadeIn = "FadeIn"
(tween tag)EFFECT_Brightness = "Brightness"
(value matches an effect name)ANIM_Idle = "Idle"
(value matches an animation name)
...or you can even add the names of the related family or object type, so there's no reuse between different types:
TIMER_Player_Invincibility = "Player_Invincibility"
TWEEN_Enemy_Opacity_FadeIn = "Enemy_Opacity_FadeIn"
(also includes the "type" of tween - in this case, opacity)EFFECT_Item_Brightness = "Brightness"
ANIM_Enemy_Idle = "Idle"
ANIM_Player_Idle = "Idle"
Lately I've been doing the latter which has two additional benefits:
- Less confusion when finding references, since every name is specific to an object type or a family
- Less typing / better autocompletion: eg. I can type ANIM_ to get a list of all animation names, continuing typing the object/family name filters the list even further so it's easy to choose one with the arrow keys
- Tidier vNames sheet: alphabetically sorting global names means they are grouped by type and object / family.