SolvedHow-toUpdated

The Farmer Was Replaced: From Zero to AFK Walkthrough: Starter Scripts + Full Auto Farm

Short answer

Step-by-step walkthrough for players with no coding experience. Start with tiny paste-and-run scripts to farm hay, wood, and carrots. Unlock the coding basics, then switch to one full AFK main script that buys unlocks and grows into power, dinosaurs, mazes, and multi-drone farming.

Steam Community guide by PrisonedLotus.

Intro

This guide takes you from no coding experience to a full AFK script called afk_farm that farms, buys unlocks, and later runs power, dinosaurs, and mazes by itself.
Path: Steps 1–5 (you buy unlocks on the tree) → starter_6 (prove unlock() works) → afk_farm (full AFK).
GitHub (full afk_farm script + starters):
https://github.com/PrisonedLotusGaming/The-Farmer-Was-Replaced/tree/main/guides/afk-farm
Most important fact: Auto Unlock (unlock()) costs 5k pumpkins and sits at the end of the coding branch. You also need Dictionaries and Costs first (2.5k pumpkins each). Until then, starters only farm. You click the tree yourself.

Unlock Order (Follow This On The Tree)

Buy in this order. First unlock prices shown. Prefer Speed ranks whenever they are cheap. Buy Watering early (about 50 wood) so crops grow faster.
Plant costs: hover plant() for your amounts. Carrots spend hay + wood. Pumpkins spend carrots. Crop upgrades raise those costs. Starters keep feed crops on other tiles so you do not need a separate stockpile grind. Pumpkins also need a solid square (up to 6x6) for giant yield; feed crops stay outside that square.
Expand ranks: farm size jumps when you buy Expand (not +1 each time).

  • 1st (Step 2): 1 → 1x3 for the mixed hay/bush/carrot column
  • 2nd (Step 3): 1x3 → 3x3 after Variables, with the full-farm maintain script
  • Later: buy Expand before Lists / the pumpkin grind. Sizes keep jumping (example 8x8 → 12x12). At 8x8 the script uses a 6x6 pumpkin square + feed rim; 12x12 makes that rim much larger. Check the tree for the next size.
  • Loops - tutorial
  • Speed - 20 hay (buy more ranks often)
  • Plant - 50 hay
  • Expand 1st - 30 hay (1x3)
  • Watering - about 50 wood (buy as soon as bushes can fund it; faster growth)
  • Carrots - 50 wood
  • Mixed 1x3 hay + bush + carrot script (Step 2), with watering
  • Operators - 150 hay + 10 wood
  • Senses - 100 hay
  • Variables - 35 carrots
  • Expand 2nd (3x3) + full-farm hay/bush/carrot script (Step 3)
  • Functions - 40 carrots
  • Trees - 50 wood + 70 carrots
  • Lists - 500 carrots
  • Pumpkins - 500 wood + 200 carrots
  • Dictionaries - 2.5k pumpkins
  • Costs - 2.5k pumpkins
  • Auto Unlock - 5k pumpkins
    Optional: Grass ranks (hay yield), more Watering ranks (more tanks), Debug (50 hay + 50 wood).
    When Auto Unlock is owned: After Auto Unlock (starter_6), then afk_farm.

How To Use Any Script In This Guide

  • Open a code window in game.
  • Rename it to the step's window name (example: starter_1).
  • Clear it, paste the step's code, run it.
  • While it farms, buy what that step lists under Buy next / Buy while it runs.
  • When the step says to move on: stop the script, rename the same window, clear it, paste the next code, run again.
    One window is enough. Keep the tabs when you paste (indentation matters in this game). Buy Speed whenever it is cheap.
    Window names
  • Step 1 hay: starter_1
  • Step 2 wood then carrots: starter_2
  • Step 3 full farm: starter_3
  • Step 4 trees: starter_4
  • Step 5 pumpkins: starter_5
  • After Auto Unlock: starter_6
  • Then: afk_farm

Walkthrough

Follow Step 0 through Step 5 in order. One code window. Swap the script when the step says so. Do not paste afk_farm until you own Auto Unlock and starter_6 runs clean.
These rules show up in the steps too. Read them once here so the steps make sense.
Speed: Buy Speed ranks whenever they are cheap. Everything gets faster permanently.
Watering: Buy as soon as you can (about 50 wood, right after bushes). Watered crops grow much faster (up to about 5x). Free water tanks refill over time. From Step 2 on, scripts water tiles as they go.
Plant costs (hover plant() in-game for your numbers):

  • Carrot: hay + wood each plant (cost rises when you upgrade Carrots)
  • Pumpkin: carrots each plant (cost rises when you upgrade Pumpkins)
  • Bush / Tree: free
    Do not grind a huge stockpile then switch crops. Early scripts keep hay and wood growing on other tiles while carrots run. Pumpkins need a solid square (up to 6x6) plus a hay-heavy feed rim (carrots still grow there too). Prefer Speed / Expand / Grass / Watering over upgrading Carrots/Pumpkins early, or plant cost gets very high.
    Expand: 1st = 1 → 1x3. 2nd = 1x3 → 3x3. Later sizes jump (example 8x8 → 12x12). Check the tree for the next size.

Step 0

  1. Finish the in-game coding tutorial until you unlock Loops (while).
  2. Buy Speed (20 hay). Buy the 1st Expand in Step 2 (after Plant), not yet.
    Then go to Step 1.

Step 1

Goal: AFK hay on your starting tile so you can afford Plant.
Must already own:

  • Loops
  • Speed
    Buy next:
  • Speed ranks when cheap
  • Plant (50 hay)
  • Do not buy Expand yet (starters stay single-tile for now)
    Window name: starter_1
    Rename the window to starter_1, clear it, paste this, and run:
    while True:
    if can_harvest():
    harvest()
    No move() yet. That is fine on one tile.
    When you own Plant, go to Step 2 immediately (you need wood before Carrots).

Step 2

Goal: 1st Expand (1x3), unlock Watering + Carrots, then one script that grows hay + wood + carrots together (and waters). Buy Operators + Senses while it runs.
Expand reminder: 1st purchase = 1x3. 2nd = 3x3 (Step 3). Later sizes jump (example 8x8 → 12x12).
Watering: Buy as soon as you have about 50 wood. Watered crops grow much faster. Free tanks refill over time. Before Operators, scripts just call use_item(Items.Water). After Operators (Step 3+), they only water when the tile is dry.
Why mixed tiles: Each carrot spends hay + wood (hover plant() for the amount). This script farms hay and wood on the other two tiles so planting can keep going.
Do this in order:
1) 1st Expand - buy Expand (30 hay) for 1x3. More hay on starter_1 first if needed.
2) Bushes for wood - rename to starter_2, paste, run. Buy Watering (~50 wood) as soon as you can, then unlock Carrots (50 wood).
while True:
if can_harvest():
harvest()
plant(Entities.Bush)
use_item(Items.Water)
move(North)
After you own Watering, the use_item(Items.Water) line starts working. If you pasted it slightly early and it errors: buy Watering, then run again.
3) One-time till (carrot tile only) - stand on the tile you want for carrots, run this once, then stop. Only that tile should become Soil. (till() toggles Soil and Grassland. Running it twice undoes it.)
till()
4) Maintain script (hay + wood + carrots + water) - stand on that Soil tile first. Moving North each loop, the column order is: carrot → hay → bush. Paste and run. Do not put till() in this loop.
while True:
if can_harvest():
harvest()
plant(Entities.Carrot)
use_item(Items.Water)
move(North)
if can_harvest():
harvest()
use_item(Items.Water)
move(North)
if can_harvest():
harvest()
plant(Entities.Bush)
use_item(Items.Water)
move(North)
If carrot plant() does nothing, you are short on hay or wood. Leave this running; the hay and bush tiles refill it.
5) Buy while it runs:

  • Operators (150 hay + 10 wood)
  • Senses (100 hay) right after
  • More Watering ranks if cheap (more tanks)
  • Speed if cheap
  • Skip 2nd Expand until Step 3
    Then go to Step 3.

Step 3

Goal: Buy Variables and the 2nd Expand (3x3), then run a full-farm script that keeps hay, wood, and carrots going, and waters dry tiles.
Must already own from Step 2: Operators, Senses, Watering, Carrots (safe till() and get_water() need those).
Plant cost: every carrot spends hay + wood. About 1/3 grass (hay), 1/3 bushes (wood), 1/3 carrots.
Watering: You should already own Watering from Step 2. This script only waters when get_water() < 0.5 so you do not waste tanks.
Do:

  • Keep Step 2 running until you can buy Variables (35 carrots).
  • Buy the 2nd Expand (3x3).
  • Rename to starter_3, clear, paste below, run.
  • Buy Functions (40 carrots), more Expand / Speed / Watering when cheap, then Trees (50 wood + 70 carrots).
    while True:
    size = get_world_size()
    x = 0
    while x < size:
    y = 0
    while y < size:
    if can_harvest():
    harvest()
    kind = (get_pos_x() + get_pos_y()) % 3
    if kind == 0:
    if get_ground_type() != Grounds.Grassland:
    till()
    elif kind == 1:
    if get_ground_type() != Grounds.Grassland:
    till()
    plant(Entities.Bush)
    else:
    if get_ground_type() != Grounds.Soil:
    till()
    plant(Entities.Carrot)
    if get_water() < 0.5:
    use_item(Items.Water)
    move(North)
    y = y + 1
    move(East)
    x = x + 1
    What each tile does:
  • kind 0: Grassland hay
  • kind 1: Bush (wood)
  • kind 2: Carrot
  • Then water if the tile is under half full
    When you own Trees, go to Step 4.

Step 4

Goal: Better wood from a few spaced trees, plus hay and carrots. Grind Lists, then unlock Pumpkins.
Must already own: Variables, Functions, Trees
Plant cost: carrots spend hay + wood. Hay tiles refill hay; trees refill wood (trees drop more wood than bushes, so you do not need many).
Trees: Only about 1/4 of tiles are trees, on a spaced grid so none sit north/south/east/west of another tree (adjacent trees grow much slower).
Do:

  • Rename to starter_4, clear, paste, run.
  • Buy Lists (500 carrots). Buy more Expand before that if you can.
  • Buy Pumpkins (500 wood + 200 carrots) when ready. Buy Speed / Grass / Watering when cheap.
    while True:
    size = get_world_size()
    x = 0
    while x < size:
    y = 0
    while y < size:
    if can_harvest():
    harvest()
    spot = get_pos_x() + get_pos_y()
    if spot % 4 == 0:
    if get_ground_type() != Grounds.Grassland:
    till()
    plant(Entities.Tree)
    elif spot % 4 == 1:
    if get_ground_type() != Grounds.Grassland:
    till()
    else:
    if get_ground_type() != Grounds.Soil:
    till()
    plant(Entities.Carrot)
    if get_water() < 0.5:
    use_item(Items.Water)
    move(North)
    y = y + 1
    move(East)
    x = x + 1
    Tile guide:
  • spot % 4 == 0: Tree (sparse + not beside other trees)
  • spot % 4 == 1: Grassland hay
  • spot % 4 == 2 or 3: Carrot
  • Water any tile under half full
    When you own Pumpkins, go to Step 5.

Step 5

Goal: Farm pumpkins for Dictionaries / Costs / Auto Unlock (~10k total: 2.5k + 2.5k + 5k) with a solid pumpkin square for giant yield, and a feed rim that can pay plant costs.
Why a square: An n x n of fully grown pumpkins merges into a giant (best at 6x6). About 1 in 5 die and block the merge; Dead_Pumpkin must be cleared with plant(Entities.Pumpkin). Never put feed crops inside the square.
Expand tip: Farm size jumps (example 8x8 → 12x12). When that happens, old carrot tiles can sit inside the new pumpkin square. This script harvests wrong crops and replants pumpkins there. It only counts a tile as ready when the entity is actually a Pumpkin.
Cost ratio: Pumpkins spend carrots. Carrots spend hay + wood. Feed rim is mostly hay, then some carrots, sparse trees.
Square size: about half the farm until 8x8, then a fixed 6x6 pumpkin square (max giant multiplier) with the rest as feed. On 12x12 that feed rim is large.
Do:

  • Buy Expand often. Get to 8x8 for a 6x6 pumpkin square + rim; 12x12 is even better for funding plant costs.
  • Rename to starter_5, clear, paste, run. Leave it AFK while you watch the unlock tree.
  • Buy in order: Dictionaries, then Costs, then Auto Unlock. Buy Speed / Watering when cheap.
    while True:
    size = get_world_size()
    n = size // 2
    if size >= 8:
    n = 6
    if n > 6:
    n = 6
    if n > size:
    n = size
    if n < 1:
    n = 1
    ready = 0
    dead = 0
    x = 0
    while x < size:
    y = 0
    while y < size:
    px = get_pos_x()
    py = get_pos_y()
    if px < n and py < n:
    if get_ground_type() != Grounds.Soil:
    till()
    entity = get_entity_type()
    if entity == Entities.Dead_Pumpkin:
    dead = dead + 1
    plant(Entities.Pumpkin)
    elif entity == Entities.Pumpkin:
    if can_harvest():
    ready = ready + 1
    else:
    if can_harvest():
    harvest()
    plant(Entities.Pumpkin)
    else:
    if can_harvest():
    harvest()
    spot = px + py
    if spot % 8 == 0:
    if get_ground_type() != Grounds.Grassland:
    till()
    plant(Entities.Tree)
    elif spot % 8 <= 5:
    if get_ground_type() != Grounds.Grassland:
    till()
    else:
    if get_ground_type() != Grounds.Soil:
    till()
    plant(Entities.Carrot)
    if get_water() < 0.5:
    use_item(Items.Water)
    move(North)
    y = y + 1
    move(East)
    x = x + 1
    if dead == 0:
    if ready >= n * n:
    while get_pos_x() != 0:
    move(West)
    while get_pos_y() != 0:
    move(South)
    if can_harvest():
    harvest()
    Pumpkin tile rules:
  • Dead_Pumpkin: replant pumpkin
  • Entities.Pumpkin + can_harvest(): count ready (do not replant)
  • Growing pumpkin: leave it
  • Anything else (carrot, grass, empty): harvest if needed, then plant pumpkin
  • When dead == 0 and all n * n tiles are ready pumpkins: walk to (0,0) and harvest()
    Feed rim: ~1/8 trees, ~5/8 hay, ~1/4 carrots.
    When you own Auto Unlock, go to After Auto Unlock.

After "Unlock()" Obtained

This section starts when you own Auto Unlock (unlock()). Use a tiny auto-buyer to prove code can unlock things, then switch to afk_farm.

Tiny auto-buyer (starter_6)

Goal: Prove unlock() works, keep hay/wood topped up so farming does not stall, then move to afk_farm.
Must already own:

  • Everything in Unlock Order through Auto Unlock
  • starter_5 pumpkin farm was working
    Window name: starter_6
    Stop starter_5, rename to starter_6, clear it, paste this, and run:
    def buy():
    unlock(Unlocks.Speed)
    unlock(Unlocks.Expand)
    unlock(Unlocks.Plant)
    unlock(Unlocks.Grass)
    unlock(Unlocks.Watering)
    unlock(Unlocks.Trees)
    unlock(Unlocks.Carrots)
    unlock(Unlocks.Pumpkins)
    unlock(Unlocks.Fertilizer)
    unlock(Unlocks.Sunflowers)
    unlock(Unlocks.Cactus)
    unlock(Unlocks.Mazes)
    unlock(Unlocks.Polyculture)
    unlock(Unlocks.Dinosaurs)
    unlock(Unlocks.Megafarm)
    unlock(Unlocks.Hats)
    unlock(Unlocks.Debug)
    unlock(Unlocks.Debug_2)
    def farm_once():
    size = get_world_size()
    buffer = size * size
    if buffer < 100:
    buffer = 100
    x = 0
    while x < size:
    y = 0
    while y < size:
    if can_harvest():
    harvest()
    hay = num_items(Items.Hay)
    wood = num_items(Items.Wood)
    spot = get_pos_x() + get_pos_y()
    if hay < buffer or wood < buffer:
    if hay <= wood:
    if get_ground_type() != Grounds.Grassland:
    till()
    else:
    if get_ground_type() != Grounds.Grassland:
    till()
    if spot % 2 == 0:
    plant(Entities.Tree)
    else:
    if get_ground_type() != Grounds.Soil:
    till()
    plant(Entities.Carrot)
    if get_water() < 0.5:
    use_item(Items.Water)
    move(North)
    y = y + 1
    move(East)
    x = x + 1
    while True:
    buy()
    farm_once()
    Success check: the window keeps looping, and unlocks buy themselves when you can afford them.
    What farm_once does:
  • Buffer = world size squared (at least 100)
  • If hay or wood is under that buffer, farm the lower one (grass for hay; checkerboard trees for wood)
  • Only plant carrots when both look healthy
  • Waters dry tiles
    Notes:
  • If an Unlocks.Name errors on load, delete that one unlock(...) line and try again.
  • Do not put Loops / Operators / Variables / Lists / Functions / Dictionaries / Auto Unlock in this buy list before you own them.
    When starter_6 runs clean, go to the next section: Afk_farm Script.

Afk_farm Script

The full script is too long for Steam, so it lives on GitHub as afk_farm.txt.
Must already own:

  • Everything in Unlock Order through Auto Unlock
  • starter_6 runs without errors
    Window name: afk_farm
    Install from GitHub
  • Open: https://github.com/PrisonedLotusGaming/The-Farmer-Was-Replaced/tree/main/guides/afk-farm
  • Open afk_farm.txt, click Raw, then select all and copy.
  • Stop starter_6.
  • Rename the code window to afk_farm.
  • Clear it, paste the full file, run it.
  • Leave it AFK.
    The same folder also has starter_1.txt through starter_6.txt if you want the starters from files instead of this guide.
    From here, afk_farm farms and calls unlock() on its PRIORITY list when you can afford items. It keeps hay/wood topped up for carrot plant costs, grows a solid pumpkin square for giants, and waters as it goes. Megafarm is not required to start; extra drones turn on automatically after you unlock it. See Using afk_farm for what each unlock adds.

Using Afk_farm

What afk_farm does each cycle

  • Checks power (after you own Sunflowers)
  • Buys unlocks it can afford with unlock()
  • Farms the field (1 pass, or 3 after you own Polyculture)
  • Runs dinosaurs when you own Dinosaurs + Hats and have food ready
  • Runs mazes when you own Mazes and have Weird Substance ready
    Missing features are skipped until unlocked. Early cycles are often farm + buy only. That is normal. You do not need to rewrite windows for each new system.

What unlocks turn on inside afk_farm

  • Watering: waters tiles under half full (faster growth)
  • Pumpkins: solid pumpkin square, replants Dead_Pumpkin, waits for giant, harvests at origin
  • Cactus: grows, sorts, then harvests the cactus square
  • Sunflowers: north sunflower strip + automatic power restock
  • Polyculture: farms 3 times per cycle
  • Megafarm: uses extra drones to go faster (until then, everything runs on one drone)
  • Hats + Dinosaurs: bone runs (can shrink to 8x8 with Debug_2, then restore; bails if the snake gets stuck)
  • Mazes: Weird Substance maze treasure runs

Late farm layout

  • Southwest: pumpkin square (6x6 on 8x8/12x12; half-field on bigger farms)
  • Southeast: cactus square (same size)
  • Top rows: sunflowers (after unlock)
  • Free tiles: hay-heavy feed mix; sparse trees; carrots only when hay/wood stocks are healthy
  • If hay or wood runs low, free tiles refill that resource before planting more carrots

Normal things that look scary

  • The whole farm becomes sunflowers, then returns to normal: power restock (Sunflowers).
  • The farm shrinks during dinosaur mode, then returns: fast 8x8 dino clear (Debug_2).
  • It prints dino bail then continues: the snake got stuck; bones still harvest when the hat comes off.
  • Early afk_farm ignores mazes or dinosaurs: waiting for Mazes / Dinosaurs / Hats and the matching resources.
  • It never stops alone: stop the code window when you want control back.

Troubleshooting

  • unlock() / Auto Unlock errors
    You do not own Auto Unlock yet. Keep using Step 5 (pumpkins). You need Dictionaries (2.5k), Costs (2.5k), and Auto Unlock (5k).
  • "Unlocks.Variables must be unlocked..."
    Own Variables first (35 carrots). Buy it from the tree. Do not put Unlocks.Variables in a buy list before you own it.
  • Error about lists or [ ]
    Unlock Lists (500 carrots), then paste again.
  • Error about def / functions
    Unlock Functions (40 carrots), then paste again.
  • Error about dictionaries / { }
    Unlock Dictionaries (2.5k pumpkins), then buy Costs and Auto Unlock.
  • Unlocks.Name error in starter_6 / afk_farm
    Delete that one unlock(...) line, or that one line from PRIORITY at the top of afk_farm, and run again.
  • till() flipped the wrong ground
    till() toggles Soil and

Did this work for you?

More for The Farmer Was Replaced

All The Farmer Was Replaced guides →

SolvedHow-to

RoboCulture 101: Python for Beginners

✨ Updated for Release 1.0 ✨ Goal: To equip beginners with the foundational knowledge to ask informed questions and understand advanced programming tutorials (e.g., on YouTube). About This Guide: This workbook is for individuals new to coding who may face an experience paradox, where you have to…

SolvedHow-to

Unlocking the "Full Automation" Achievement: A Quick Workflow!

Goal: You’re one step away from platining the game—only the Full Automation achievement remains. Challenge: Not sure where to start or feeling unmotivated? No problem. Solution: Use this script as a skeleton to unlock the achievement. It’s compatible with the October 2025 update and can be…

#achievement

SolvedHow-to

Decimalist's Code

Collection of my code. Includes: Parallelization --- Cactus: Shakersort --- Sunflower: Buckets --- Pumpkin: Queue --- Polyculture: random Chain or special-crop --- Maze: Multidrone Cheese