CognitoCoding All posts
The Weird Substance Nobody Saw Coming — The Farmer Was Replaced Ep 7
17 July 2026 3 min read by Eris Taylor

The Weird Substance Nobody Saw Coming — The Farmer Was Replaced Ep 7

pythonthe-farmer-was-replacedlearn-to-codebeginnersbehind-the-build

By the end of Episode 6, the drone had a bubble sort, a cactus rotation, and a farm that mostly ran itself.

Episode 7 added fertiliser. Simple idea — drop it on a crop and it grows instantly. No waiting. No checking if it is ready.

It became a problem almost immediately.

What fertiliser actually does

When you use fertiliser on a bush or crop, it skips the growth timer completely. The next harvest happens right away.

But when you harvest that fertilised crop, something unexpected falls out of it: a Weird Substance.

This is a new item type. One the drone's code had never been told about.

Here is roughly what the code was doing before Ep 7:

for entity in get_entities():
    if entity_type(entity) == EntityType.Bush:
        if num_items(Items.Bush) < num_items(Items.Fertilizer):
            use_item(Items.Fertilizer)
        if can_harvest():
            harvest()

The harvest happens. The drone picks up whatever falls out. Nobody checks what fell out — because up to this point, it was always just the crop.

Then the Weird Substance turned up in the inventory. And suddenly the code needed to care.

Why this breaks the old approach

The code up to Ep 6 assumed one outcome per harvest. Fertiliser introduced a second outcome — same action, different result depending on what was used before the harvest.

This is a pattern you will run into constantly once code starts doing real things:

You write for the case you expect. Reality sends you a case you did not.

The fix is one extra check — after harvesting, look at what actually dropped and do something different based on what it is:

# harvest happened — now check what we got
if num_items(Items.WeirdSubstance) > 0:
    # this item needs different handling to the normal crop
    # trade it, store it, or use it — but the code now knows it exists
    pass

The farm now has two paths. One for a normal harvest. One for the unexpected new item.

The concept this is really teaching

This is conditional branching on output type.

You have already seen if statements checking whether something is ready. This takes the same idea further — now you are checking what kind of thing you got back, and doing something different depending on the answer.

This shows up everywhere once you move beyond game code:

  • An API response that sometimes includes an extra field you did not expect
  • A function that returns different values depending on the input it got
  • A list where some items need different processing to others

The pattern is always the same: check what you got, then decide what to do with it. Your code should never assume there is only one possible outcome.

What to look for in the video

Watch the moment the Weird Substance shows up for the first time. The existing code does not handle it — that is the problem the whole episode is built around.

The full project code for Ep 7 is on GitHub so you can pull it down and experiment:

🔗 Episode 7 code on GitHub

▶️ Watch Episode 7 — The Weird Substance Problem Nobody Saw Coming:

The Weird Substance Problem Nobody Saw Coming — The Farmer Was Replaced Ep 7

If you are working through the series from the beginning, the earlier episodes are all on the channel. Each one adds one new concept — by Ep 7 you have got variables, operators, functions, lists, sorting, and now: handling the unexpected.


Cognito Coding — Learning To Code By Solving Real Problems.