# Why is my variable nil and does not increment?

**URL:** <https://forum.farmbot.org/t/why-is-my-variable-nil-and-does-not-increment/9680>\
**Category:** Sequences\
**Created:** [February 27, 2025, 7:59pm UTC](https://forum.farmbot.org/t/why-is-my-variable-nil-and-does-not-increment/9680 "2025-02-27T19:59:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbourre](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/n/7993a0/32.png) [@nbourre](https://forum.farmbot.org/u/nbourre)\
**Post date:** [February 27, 2025, 7:59pm UTC](https://forum.farmbot.org/t/why-is-my-variable-nil-and-does-not-increment/9680/1 "2025-02-27T19:59:30Z")

</div>

Hey guys,

I’m create a grid traveling sequence which would home all axis every time the farmbot changes row.

The script is quite simple, but I can’t figure out why, the variable `seed_count` does not increment and stays at nil value.

Here’s a snippet of my code

```lua
grid_points = variable("Number of points")
tray = variable("Seed Tray")

depart = variable("Starting location")
off_x = tonumber(env("padding_x"))
off_y = tonumber(env("padding_y"))

depart.x = depart.x + off_x
depart.y = depart.y + off_y

cell_depth = 15
vacuum_pump_pin = 9
seed_depth = tonumber(env("planting_depth"))

-- if verify_tool() then
-- send_message("info", "Dismounting tool")
-- dismount_tool()
-- end

-- send_message("info", "Mounting Seeder tool")
-- mount_tool("Seeder")

local grid = grid ({
  grid_points = grid_points,
  start = depart,
  spacing = variable("Spacing")
})

job = "Pick and Plant x" .. grid.total

set_job(job)

local seed_count = 0

grid.each(function(cell)
    
    seed_count = seed_count or 0
    seed_count = seed_count + 1

    -- error here : seed_count is nil. Why
    send_message("Info", "Going for seed : " .. tostring(seed_count))

    -- This part is ignored because seed_count is nil
    if ((seed_count % grid_points.y)== 0) then
        send_message("info", "recalibration, " .. "seed_count:" .. seed_count)
        move_absolute({z = safe_z()})
        find_home("all")
    end

   --- More code 

end)

-- some code

```

Thank you

---

<div class="post-metadata">

**Author:** ![Gabriel](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/g/9de0a6/32.png) [@Gabriel](https://forum.farmbot.org/u/Gabriel)\
**Post date:** [February 28, 2025, 12:23am UTC](https://forum.farmbot.org/t/why-is-my-variable-nil-and-does-not-increment/9680/2 "2025-02-28T00:23:55Z")

</div>

`grid.each` is run in a separate process without access to `seed_count`. You may try using `cell.count` instead.

---

<div class="post-metadata">

**Author:** ![nbourre](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/n/7993a0/32.png) [@nbourre](https://forum.farmbot.org/u/nbourre)\
**Post date:** [February 28, 2025, 2:07pm UTC](https://forum.farmbot.org/t/why-is-my-variable-nil-and-does-not-increment/9680/3 "2025-02-28T14:07:55Z")

</div>

Thanks! Is that a Lua thing or specific to the Farmbot API?

I’ll fork the documentation repo to add this info.
