Tier 1
Series 3
3A: The Magic Number Trap
"A mechanic doesn't weld a part onto a ship at exactly 45.2 degrees and then throw away the blueprint. If you need to adjust that angle later, you're in trouble. In code, a Magic Number is a value appearing out of nowhere without a label. A skilled Engineer audits for Named Constants."
The Concept: Named Constants
A "Magic Number" is any numerical value used in a calculation that isn't explained by a variable name.
Global Tuning: Change the value once at the top of the script to update the whole system.
Readability: "if(speed > MAX_VELOCITY)" is easier to audit than "if(speed > 450.0f)".
Inspector Access: Using [SerializeField] allows you to tune variables in real-time.
Global Tuning: Change the value once at the top of the script to update the whole system.
Readability: "if(speed > MAX_VELOCITY)" is easier to audit than "if(speed > 450.0f)".
Inspector Access: Using [SerializeField] allows you to tune variables in real-time.
Red Flag Detected
The AI Trap: "The Hardcoded Pilot"
You ask the AI: "Make the ship take damage when it hits something."
// AI-Generated Code: Rigid and Unsafe
void OnCollisionEnter(Collision collision) {
// Audit Fail: What is 10.0f? Why is it here?
// How do we change it later without re-compiling?
health -= 10.0f;
}
This is "Logic Rigidity." If you decide the game is too hard and want to reduce damage to 5, you have to hunt through every script to find where 10.0f was typed. A professional pilot demands a variable vault.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Mechanic's Correction
Corrective Protocol
// Corrected: The value is now labeled and tunable in the Inspector
[SerializeField] private float collisionDamage = 10.0f;
void OnCollisionEnter(Collision collision) {
health -= collisionDamage;
}
Your Pilot Command
> Implement the Singleton pattern to ensure a unique global instance.