A Bot “Outstanding in its Field”
Image by 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 - 1, y faceLoc xrange, 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.
Stardew Valley Crops Guide
Stardew Valley Farming
Stardew Valley Farmtronics Mod
Stardew Valley Robot Mod
Stardew Valley Mod Adds Farming Bots
Stardew Valley Mod Lets Robots Do the Work
Also In The February 2023 Issue
If aliens exist, why haven’t we met any yet?
Learn how the origins of cybernetics may pave the way for the future of machine learning
Don’t let the name fool you, this systems programming language is anything but rusty!
With every end, there is a new beginning. Especially in creative robotics!
Don’t forget your umbrella for this TIC-80 Lab
Save time with this neat OpenSCAD shortcut
Time to get inspired by mother nature!
Learn how drones are being used to repair the Great Wall of China and find ancient structures!
These robot mice move like mechanical cats are chasing them!
Try out this Zombie Survival mod for Minecraft if you dare!
This trash loving AI joins the fight for a greener earth!
Spice up your 3D-printed food with time!
Now that you have made your masterpiece, it is time to share it with the world.
Time to get your Farming robots’ hands dirty!
Be the FIRST at your school to join this awesome program
Links from the bottom of all the February 2023 articles, collected in one place for you to print, share, or bookmark.
Explore the scientific origins of memes!