
In Level 1, we dropped our "Citadel" (the Smart Contract) onto the Ethereum grid. Itโs a safe, empty fortress. But a factory without a product is just a building.
Today, we are installing the most important part of our factory: The Storage Vaults. We need a way to define what a Zombie is and a place to keep an infinite army of them.
๐งฌ Step 1: The DNA Blueprint (Structs)
In a strategy game, every unit has "Stats"โHP, Mana, Attack Power. In our factory, every Zombie has DNA.
Instead of making separate boxes for every stat, Solidity lets us create a Struct. Think of a struct as a Technical Manual or a Blueprint that groups all the characteristics of a unit together.
Solidity
struct Zombie {
string name;
uint dna;
}
๐๏ธ Player Vision: You walk into the center of the citadel and install a holographic terminal. This terminal defines the "Species." Every Zombie created from now on MUST follow this blueprint: It must have a Name and a DNA code.
๐ฆ Step 2: The Infinite Army (Arrays)
Now that we have a blueprint, where do we keep the Zombies once they are built? We need a List.
In Solidity, we use an Array. Think of this like a Infinite Baracks. Every time a new Zombie is born, it gets a bunk bed in these barracks and an ID number.
Solidity
Zombie[] public zombies;
๐๏ธ Player Vision: You pull a lever, and the floor of your fortress opens up to reveal a massive, underground storage hanger. It's empty for now, but it's labeled "THE ARMY." Because itโs public, anyone can look through the glass floor and see how many Zombies you have.
๐ข Step 3: Setting the "Physics" of DNA (State Variables)
We want our Zombie DNA to be exactly 16 digits long. To do this, we need a mathematical constant. We use a State Variable.
State Variables are "Hard-coded" into the blockchain. They are like the Laws of Physics in your game world.
Solidity
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
๐๏ธ Player Vision: On the wall of your factory, you bolt down a massive brass plate. It says: "DNA LIMIT: 16 DIGITS." This rule is now permanent. The factory's machines will use this plate to make sure no Zombie is born with a 17-digit mutation.
๐ ๏ธ The Full Code (Level 2)
Here is how our ZombieFactory.sol looks now:
Solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.6.0;
contract ZombieFactory {
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
}
๐ Level 2 Cleared
We have the Blueprint (Struct), the Barracks (Array), and the Laws of Physics (State Variables).
Our factory is now "Data Ready." But wait... the machines aren't moving yet. We have the storage, but we don't have the Functions to actually create the Zombies.
In Level 3, we will build the "Creation Engine"โthe functions that take a name and turn it into a living, breathing (well, undead) monster.
Is your DNA vault ready? Drop a ๐งฌ in the comments if you're following the quest!
United States
NORTH AMERICA
Related News
What Does "Building in Public" Actually Mean in 2026?
20h ago
The Agentic Headless Backend: What Vibe Coders Still Need After the UI Is Done
20h ago
Why Iโm Still Learning to Code Even With AI
22h ago
I gave Claude a persistent memory for $0/month using Cloudflare
1d ago
NYT: 'Meta's Embrace of AI Is Making Its Employees Miserable'
1d ago
