The Farmer Was Replaced

The Farmer Was Replaced

multiple drones
cant get multiple drones to work. saw a coment in another discussion but it didnt work.
multiple drons cant work with infinate while loops?
< >
Showing 1-15 of 24 comments
Can you be more specific? What, exactly, isn't working?
Can you show us some code that demonstrates the problem?

Multiple drones is working just fine for me.
def mainwork():
while True:
get_water()
if get_ground_type()!=Grounds.Soil:
till()
if get_pos_y()==0 or get_pos_y()==2:
if can_harvest():
harvest()
if get_ground_type()!=Grounds.Soil:
till()
if get_pos_x()%2==1:
if can_harvest():
harvest()
plant(Entities.Tree)
else:
if can_harvest():
harvest()
plant(Entities.Bush)
move(East)
if get_pos_y()==1:
if get_pos_x()%2==0:
if can_harvest():
harvest()
plant(Entities.Tree)
else:
if can_harvest():
harvest()
plant(Entities.Bush)
move(East)
if get_pos_y()>2 and get_pos_y()<6:
if can_harvest():
harvest()
if get_ground_type()!=Grounds.Soil:
till()
plant(Entities.Carrot)
move(East)
if get_pos_y()==6 or get_pos_y()==7 or get_pos_y()==8:
if can_harvest():
harvest()
plant(Entities.Grass)
move(East)
if get_pos_y()>8 and get_pos_y()<18:
if can_harvest():
harvest()
plant(Entities.Pumpkin)
if get_entity_type()==Entities.Dead_Pumpkin:
plant(Entities.Pumpkin)
move(East)

if get_pos_y()>17:
if can_harvest():
harvest()
plant(Entities.Sunflower)
move(East)
use_item(Items.Water)
if get_pos_x()==0:
move (North)

def secwork():
while True:
if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None:
plant(Entities.Pumpkin)
if get_pos_y()>17:
if can_harvest():
harvest()
plant(Entities.Sunflower)
move(West)
if get_pos_x()==0:
move (North)

def drone_example():

while True:
if num_drones() < max_drones():

spawn_drone(mainwork())

spawn_drone(secwork())
move(East)





if __name__ == "__main__":

drone_example()
Use [code] your code here [/code] to keep Steam from wrecking your formatting. Turns that wall of difficult-to-read text into this:
def mainwork(): while True: get_water() if get_ground_type()!=Grounds.Soil: till() if get_pos_y()==0 or get_pos_y()==2: if can_harvest(): harvest() if get_ground_type()!=Grounds.Soil: till() if get_pos_x()%2==1: if can_harvest(): harvest() plant(Entities.Tree) else: if can_harvest(): harvest() plant(Entities.Bush) move(East) if get_pos_y()==1: if get_pos_x()%2==0: if can_harvest(): harvest() plant(Entities.Tree) else: if can_harvest(): harvest() plant(Entities.Bush) move(East) if get_pos_y()>2 and get_pos_y()<6: if can_harvest(): harvest() if get_ground_type()!=Grounds.Soil: till() plant(Entities.Carrot) move(East) if get_pos_y()==6 or get_pos_y()==7 or get_pos_y()==8: if can_harvest(): harvest() plant(Entities.Grass) move(East) if get_pos_y()>8 and get_pos_y()<18: if can_harvest(): harvest() plant(Entities.Pumpkin) if get_entity_type()==Entities.Dead_Pumpkin: plant(Entities.Pumpkin) move(East) if get_pos_y()>17: if can_harvest(): harvest() plant(Entities.Sunflower) move(East) use_item(Items.Water) if get_pos_x()==0: move (North) def secwork(): while True: if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None: plant(Entities.Pumpkin) if get_pos_y()>17: if can_harvest(): harvest() plant(Entities.Sunflower) move(West) if get_pos_x()==0: move (North) def drone_example(): while True: if num_drones() < max_drones(): spawn_drone(mainwork()) spawn_drone(secwork()) move(East) if __name__ == "__main__": drone_example()

Now that we've got that straightened out, gimme a minute to look this over.
Alright, I see two problems.

First, you shouldn't put the "()" on the function name in spawn_drone().
In drone_example(), change those to "spawn_drone(mainwork)" and "spawn_drone(secwork)".

Second, your drone functions are not built right for what you're trying to do.
Changing the "move(East)" to "move(North)" in drone_example() is a decent "quick and dirty" fix to prove that the concepts are sound, but I think you're going to want to rewrite your drone functions.

All in all, I'd say you've got the hang of this coding thing... good luck and have fun!
Oh, one more thing: you probably want your main drone to do something after it spawns all the extra drones, too... currently, your "primary" drone just stops once it's finished spawning drones.

Perhaps something like this would be better:
def drone_example(): while num_drones() < max_drones(): spawn_drone(mainwork) spawn_drone(secwork) move(North) # (yes, moving north twice; it generates a move(North) # more aesthetically pleasing pattern on a # 32x32 field with 16 drones) secwork() # final drone won't spawn because max_drones has been reached # (the "primary" drone counts against max_drones(); # num_drones() is never less than 1)
def mainwork(): while True: get_water() if get_ground_type()!=Grounds.Soil: till() if get_pos_y()==0 or get_pos_y()==2: if can_harvest(): harvest() if get_ground_type()!=Grounds.Soil: till() if get_pos_x()%2==1: if can_harvest(): harvest() plant(Entities.Tree) else: if can_harvest(): harvest() plant(Entities.Bush) move(East) if get_pos_y()==1: if get_pos_x()%2==0: if can_harvest(): harvest() plant(Entities.Tree) else: if can_harvest(): harvest() plant(Entities.Bush) move(East) if get_pos_y()>2 and get_pos_y()<6: if can_harvest(): harvest() if get_ground_type()!=Grounds.Soil: till() plant(Entities.Carrot) move(East) if get_pos_y()==6 or get_pos_y()==7 or get_pos_y()==8: if can_harvest(): harvest() plant(Entities.Grass) move(East) if get_pos_y()>8 and get_pos_y()<15: if can_harvest(): harvest() plant(Entities.Pumpkin) if get_entity_type()==Entities.Dead_Pumpkin: plant(Entities.Pumpkin) move(East) if get_pos_y()>14 and get_pos_y()<18: if can_harvest(): harvest() plant(Entities.Cactus) move(East) if get_pos_y()>17: if can_harvest(): harvest() plant(Entities.Sunflower) move(East) use_item(Items.Water) if get_pos_x()==0: move (North) def secwork(): while True: if get_entity_type() == Entities.Dead_Pumpkin or get_entity_type() == None: plant(Entities.Pumpkin) if get_pos_y()>17: if can_harvest(): harvest() plant(Entities.Sunflower) move(West) if get_pos_x()==0: move (North) def drone_example(): while True: if num_drones() < max_drones(): spawn_drone(mainwork) spawn_drone(secwork) if __name__ == "__main__": drone_example()




got another drone to spawn but only one works on a task
You forgot to move the "main" drone between spawns, so your drones are all stacked in one place.

You don't actually have to move, you just need to delay between the calls to spawn_drone(), or do something else that causes them to separate so they're not right on top of each other.
Try this:
def drone_example(): while num_drones() < max_drones(): spawn_drone(mainwork) spawn_drone(secwork) do_a_flip() secwork()

Go look at my earlier comments; I've got your code making millions of product per minute by making only the changes I talked about.

https://steamcommunity.com/sharedfiles/filedetails/?id=3622314561
THANK YOU
One final note: doing a single flip between drone spawns lets them clump back up again. Might want to do multiple flips between drone spawns, or use the earlier code I supplied that has 2 "move(North)" lines instead, so they have more separation.

This happens because when they have nothing to do (for instance, there's no harvestable crop in the square they're on), they just run at full speed while the drone in front slows down to plant or harvest or whatever.

I've also noticed that there's some weirdness in your pumpkins and/or sunflowers code that seems to stagger them oddly; you definitely want to rewrite mainwork() and secwork()... or even replace them with some more specialized code.

You could (for example) spawn a drone that waters the whole field, another drone that hangs out in the tree/bush area and plants/harvests as necessary, another drone that does carrots in the carrot area, and so forth.

EDITED TO ADD:
Found the issue with your pumpkins and sunflowers; your sunflower code is occasionally trying (and failing) to plant sunflowers on Grounds.Grassland, which leaves gaps in the pattern... and then because the pumpkins try to plant on "get_entity_type() == None", you end up with pumpkins in weird places.

Looks like your carrots are doing the same thing as the sunflowers; did you forget a till() somewhere, or maybe put it after the plant() instead of before?
OH! It's because the drones are stacking up! If more than one of them check the ground type at the same time, they all think it needs tilled, so they all till it.
Definitely need to work on that drone separation thing.
Oh, and one final thought: I was unaware that you can plant(Entities.Grass) on tilled soil... neat trick, I'll have to look into it and see if there is a benefit to doing it that way.

Usually, I just do
if get_ground_type() == Grounds.Soil: till()
because Grounds.Grassland grows hay naturally.

To be honest, I didn't even know grass could be planted; learn something new every day!
The spawn_drone function summons another drone and executes the function you provide as an argument.

So when you run your code the following happens:
It runs drone_example() on your initial drone. And keeps summoning drones until it can't summon anymore drones. Your summoned drones will do work. Either mainwork or secwork. In your code if you have 2 drones unlocked your drone will first pass the num_drones() < max_drones() check and summon a drone with mainwork. Then it will try to spawn the next drone secwork. But because you have your initial drone and the mainwork drone which is 2 drones. You won't summon a new one.

If you want to fix it you can do:
def drone_example(): spawn_drone(secwork) mainwork()
This code will make your initial drone spawn a new drone that does secwork and then start doing mainwork.
A little treat, for those who would like to see what 32 drones can do with pumpkins on a 32x32 field:
https://cdn.steamusercontent.com/ugc/9322893967541720705/95F12531922446859B3F77E6D204ADB5B0AF93A1/

"Source code" is included. Note the first two functions; being able to move to any grid coordinate you want is incredibly useful, especially when working with multiple drones.

This code hits 22M pumpkins per minute, if you uncomment the "while True" line and adjust the indentation of the rest of the function to match. It takes a couple minutes; it sticks on 18M for a good while, but will eventually pop that 20M pumpkins per minute achievement.

(This link will expire at 4:30 am Mountain Time on 14 Dec 2025) - if I remember (or someone asks), I might upload the video to YouTube and update this comment with the new link.)
Originally posted by umop-apisdn:
One final note: doing a single flip between drone spawns lets them clump back up again. Might want to do multiple flips between drone spawns, or use the earlier code I supplied that has 2 "move(North)" lines instead, so they have more separation.

This happens because when they have nothing to do (for instance, there's no harvestable crop in the square they're on), they just run at full speed while the drone in front slows down to plant or harvest or whatever.

I've also noticed that there's some weirdness in your pumpkins and/or sunflowers code that seems to stagger them oddly; you definitely want to rewrite mainwork() and secwork()... or even replace them with some more specialized code.

You could (for example) spawn a drone that waters the whole field, another drone that hangs out in the tree/bush area and plants/harvests as necessary, another drone that does carrots in the carrot area, and so forth.

EDITED TO ADD:
Found the issue with your pumpkins and sunflowers; your sunflower code is occasionally trying (and failing) to plant sunflowers on Grounds.Grassland, which leaves gaps in the pattern... and then because the pumpkins try to plant on "get_entity_type() == None", you end up with pumpkins in weird places.

Looks like your carrots are doing the same thing as the sunflowers; did you forget a till() somewhere, or maybe put it after the plant() instead of before?
OH! It's because the drones are stacking up! If more than one of them check the ground type at the same time, they all think it needs tilled, so they all till it.
Definitely need to work on that drone separation thing.


tilling is the first thing mainwork() does, so all my farm is tilled no matter what
Originally posted by Roble_Konara:
tilling is the first thing mainwork() does, so all my farm is tilled no matter what

Right, but when multiple drones till() the same square at the same time, or till() without checking, it untills, leaving grass instead of soil.

It's not a huge deal, and eventually seems to sort itself out (mostly), it's just that your drone-work functions will need some adjustment to be "perfect".
Originally posted by Roble_Konara:
cant get multiple drones to work. saw a coment in another discussion but it didnt work.
multiple drons cant work with infinate while loops?
I tried to restructure the layout you tried to achieve (I hope) while removing some redundant checks / duplicate code.
That said at this point in your farm (with multiple drones active) you really ought to use polycolture for resource production of hay/wood/carrots and algos that allows you to grow a massive NxN pumpkin or a whole field of sorted cacti.
Hope this helps
def drone_example(): def mainwork(): while True: cur_y = get_pos_y() if get_water() < 0.75: use_item(Items.Water) if get_ground_type()!=Grounds.Soil: till() if can_harvest(): harvest() if cur_y in range(0,3): if (cur_y+id)%2==0: plant(Entities.Tree) else: plant(Entities.Bush) elif cur_y in range(3,6): plant(Entities.Carrot) elif cur_y in range(6,9): plant(Entities.Grass) elif cur_y in range(9,15): plant(Entities.Pumpkin) elif cur_y in range(15,19): plant(Entities.Cactus) else: plant(Entities.Sunflower) move(North) id = num_drones() if id != 1 and get_pos_x() != get_world_size()-1: move(East) if id != max_drones() and get_pos_x() != get_world_size()-1: spawn_drone(drone_example) mainwork() if __name__ == "__main__": clear() drone_example() while num_drones() != 1: pass
< >
Showing 1-15 of 24 comments
Per page: 1530 50

Date Posted: Dec 11, 2025 @ 10:09am
Posts: 24