dark mode light mode Search Menu
Search

A Bot “Outstanding in its Field”

steamXO on Flickr

In the last issue, we presented the Farmtronics mod for Stardew Valley. You learned how to install this mod, access the Home Computer through the TV in your farmhouse, and complete the toDo tasks in order to earn your first Farmtronics robot.

Today, let’s put that robot to work.

Place your robot down outside your farm, then right-click it to bring up its computer console. If you have a big enough screen, you can left-click just below the close box (near the top-right corner of the console), hold the mouse button down, and drag to move the console so that you can see it and your robot at the same time.

Now, let’s create a startup script that adds some new functions. Use the edit command to start the code editor, then carefully type the code in the code below. When you’re done, press the Esc key to close the editor, then enter save “startup.ms” to save it to disk. Because it’s called startup.ms, it will run automatically each time your robot boots up. But since your robot has already powered up, enter run to run the program.

faceDir = function(dir)
  dir = dir % 4
  if dir < 0 then dir = dir + 4 
  while me.facing != dir 
    me.left 
   end while 
  end function 

faceLoc = function(x,y) 
 dx = x - me.position.x 
 dy = y - me.position.y 
 if abs(dx) > abs(dy) then
    if dx > 0 then target=1 else target=3
  else
    if dy > 0 then target=2 else target=0
  end if
   faceDir target
end function

(You might note that built-in robot functions now use a me prefix instead of the bot prefix mentioned in the last issue. It used to be called bot, but in version 1.3 of the Farmtronics mod, bot was changed to me.)

If running the program showed any errors, use edit again to check your work. Otherwise, try out the new commands. Entering faceDir 1 should make your robot face to the right. faceLoc 0,0 should make it face left or up, whichever way is more towards the top-left corner of the farm.

That’s a good start. Now edit again, go down to the bottom of the existing code, add a blank line, and then type in the following lines of code. This adds a goTo function, which tells the bot to go to some map location. Again exit (with the Esc key), save, and run. Now try goTo 56, 19. This should make your bot move to a point just to the left of your farmhouse. Then try goTo 52, 15, which should move it a bit further left and up. That’s going to be the area of your garden.

goTo = function(x,y)
  print "Going to " + x + ", " + y
  while me.position.x != x or me.position.y != y
    faceLoc x, y
    if me.ahead and not me.ahead.passable then me.clearAhead
    me.forward
    print "Now at " + me.position.x + ", " + me.position.y
  end while
end function

To make the bot actually garden, we need to add two more functions, shown in the code block below. You know the drill: edit, move to the bottom, and append the new code. Then exit, save, and run. You should now have a tendAhead command, which makes the bot clear, hoe, water, or harvest whatever is in front of it; and tendGarden, which makes it work the whole garden area.

tendAhead = function
  info = me.ahead
  if info != null and not info.passable then
    // some kind of obstacle: clear it
    me.clearAhead
    info = me.ahead
  end if
  if info == null then
	// empty ground: till
	me.select "hoe"
	me.useTool
	info = me.ahead
  end if
  if info.hasIndex("crop") and info.crop and
     info.crop.harvestable then
	// mature crop: harvest it!
	me.harvest
  end if
  if info.type == "HoeDirt" and info.dry then
	// dry, tilled land: water
	me.select "Watering Can"
	me.useTool
  end if
end function

tendGarden = function
  xrange = range(52, 56)
  yrange = range(15, 19)
  for y in yrange
    goTo xrange[0] - 1, y
    faceLoc xrange[0], y
    for x in xrange
      tendAhead
      me.forward
    end for
  end for
  me.forward
  faceDir 2 
end function

The only thing this program doesn’t do is plant seeds. So you’ll still need to do that step yourself. Each day when you wake up, right-click on your robot, give it a fresh (full) watering can, and then enter the tendGarden command. Then you can do other things around the farm while your robot buddy hoes, waters, and harvests your crops for you.

Learn More

Stardew Valley Crops Guide

https://www.ign.com/wikis/stardew-valley/Crops_Guide

Stardew Valley Farming

https://www.carlsguides.com/stardewvalley/farming.php

Stardew Valley Farmtronics Mod

https://www.nme.com/news/gaming-news/stardew-valley-farmtronics-mod-gives-players-a-programmable-farm-robot-3145030

Stardew Valley Robot Mod

https://www.gamesradar.com/stardew-valley-robot-mod-lets-you-leave-all-the-farm-work-to-the-machines/

Stardew Valley Mod Adds Farming Bots

https://www.pcgamer.com/stardew-valley-mod-adds-farming-bots/

Stardew Valley Mod Lets Robots Do the Work

https://www.gamespew.com/2022/01/this-stardew-valley-mod-lets-you-have-robots-do-the-hard-work/