The Farmer Was Replaced

The Farmer Was Replaced

ransom May 27, 2024 @ 9:48am
Code Mostly Works
Hi all. I'm pretty early on, but I've written some code that mostly works to accomplish my goal, which is to actively loop planting/harvesting Hay, Wood, and Carrots based on how many of them I have. This works fine as it's iterating through the first time, until it meets the conditions in order, ie: I have 600 Hay, 600 Wood, 350 Carrots, but while it's running I spend some of my Hay and Wood, so I now have, say, 200 Hay, 300 Wood, and as it's completing the Carrots section of code, topping them off to 400, it loops around to the beginning again, and I would expect it to find that Hay is no longer at 600, so it should keep parsing through that code. What it's actually doing is, after it reaches the top again, it starts cycling through the Hay code as if it's executing, but it's not actually doing anything except moving around the map. If I step through the code one-by-one, it looks like it's executing each line of code (for example plant(Entities.Grass)) -- but it isn't doing that.

Here's my code.
clear() for i in range(get_world_size()): while num_items(Items.Hay) < 600: for j in range(get_world_size()): if get_entity_type() == Entities.Grass and can_harvest(): harvest() move(North) elif get_entity_type() != Entities.Grass: plant(Entities.Grass) move(North) move(East) while num_items(Items.Wood) < 600: for k in range(get_world_size()): if get_entity_type() == Entities.Bush and can_harvest(): harvest() plant(Entities.Bush) move(North) elif get_entity_type() != Entities.Bush: plant(Entities.Bush) move(North) move(East) while num_items(Items.Carrot) < 400: for l in range(get_world_size()): if get_entity_type() == Entities.Carrots and can_harvest(): harvest() if num_items(Items.Carrot_Seed) < 1: trade(Items.Carrot_Seed) plant(Entities.Carrots) move(North) elif get_entity_type() != Entities.Carrots: till() if num_items(Items.Carrot_Seed) < 1: trade(Items.Carrot_Seed) plant(Entities.Carrots) move(North) move(East)

Thanks for any help!
Last edited by ransom; May 27, 2024 @ 9:55am
Originally posted by martino2408:
plant(Entities.Grass) doesn't work on tilled soil. You don't have to 'plant' grass. Just call till() again and it will be turned back into turf, and the grass will start growing.
< >
Showing 1-3 of 3 comments
The author of this thread has indicated that this post answers the original topic.
martino2408 May 27, 2024 @ 10:23am 
plant(Entities.Grass) doesn't work on tilled soil. You don't have to 'plant' grass. Just call till() again and it will be turned back into turf, and the grass will start growing.
ransom May 27, 2024 @ 11:43am 
Originally posted by martino2408:
plant(Entities.Grass) doesn't work on tilled soil. You don't have to 'plant' grass. Just call till() again and it will be turned back into turf, and the grass will start growing.

Awesome, that was it. Thanks so much!
ChaosEclipse1 May 28, 2024 @ 8:48am 
ran a simple test for you, code that i used is below. You can plant grass on tilled soil, and yes i do realize that clearing the field causes grass to be auto-grown but I already have a set of code for wheat that works well. Hope this helps you out.

clear()
for x in range(get_world_size()):
....for y in range(get_world_size()):
........till()
........plant(Entities.Grass)
........move(North)
....move(East)
Last edited by ChaosEclipse1; May 28, 2024 @ 8:50am
< >
Showing 1-3 of 3 comments
Per page: 1530 50