Tier 1
Series 3
3C: The String Menace
"In a cockpit, if a label is misspelled, the pilot can still understand the intent. But if a computer expects the word "LandingGear" and you type "LadinngGear", the system simply fails to respond. If your AI uses raw text strings for logic, you've created a Hidden Saboteur. A skilled Engineer audits for Enums."
The Concept: String Fragility
A "Hardcoded String" is text typed directly into your code logic. These are dangerous because the C# compiler cannot check if they are "correct"—it only checks if they are valid text.
No Logic Strings: Never use if(tag == "Enemy") if you can use an Enum.
Constants for Keys: Define them once as a const string.
Enums for States: Use Enumerations for a fixed list of options.
No Logic Strings: Never use if(tag == "Enemy") if you can use an Enum.
Constants for Keys: Define them once as a const string.
Enums for States: Use Enumerations for a fixed list of options.
Red Flag Detected
The AI Trap: "The Typosquat"
You ask the AI: "Check if the player has the 'RedKey' to open the door."
// AI-Generated Code: Fragile and Unverifiable
void OnTriggerEnter(Collider other) {
// Audit Fail: If you accidentally name the item "redkey" in the inspector,
// this logic will fail silently. No error will pop up.
if (inventory.HasItem("RedKey")) {
OpenDoor();
}
}
This is "Blind Coupling." You are forcing the code to match a string that might change or be misspelled. If the player can't open the door, you'll spend hours debugging logic when the problem was just a capital 'K'.
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 "Source of Truth"
public static class ItemKeys {
public const string RED_KEY = "RedKey";
}
void OnTriggerEnter(Collider other) {
// The IDE will now help you: typing "ItemKeys." shows you all options
if (inventory.HasItem(ItemKeys.RED_KEY)) {
OpenDoor();
}
}
Your Pilot Command
> Implement the Observer pattern using C# Events or Actions.