The Farmer Was Replaced

The Farmer Was Replaced

YourOnlyEnd Dec 23, 2024 @ 5:02pm
Reaching Call Stack Size
Great game so far, it's helping me a lot with learning Python due to a lack of motivation, slight complaint though, I think the game needs a form of destructor, or a clear way for the user to not reach the call stack and be able to loop endlessly.
The way it has been occurring is with me performing a recursive call in a function that checks my resources, the issue being that I don't know if Async functions are a thing in Python.

SIDE NOTE: I understand the Call Stack Size exists to keep the hardware usage contained as, yes, obviously it's infinite loops calling each other, because how else am I making the drone move infinitely, here's the code I am using, I didn't get that far in the game yet but here you go: (I think it's not THAT bad, and yes I know I could rephrase it to work around the issue, but this feels problematic to me.)

Sidenote: Sometimes the stem on 2x2 pumpkins doesn't render, idk if it's a design choice or not.


Reposition()
Storage_Check()


def Wood():
while True:
for i in range(get_world_size()):
if get_water()<=0.2:
use_item(Items.Water)
if can_harvest():
harvest()
if get_pos_x()%2==0 and get_pos_y()%2==0:
plant(Entities.Tree)
else:
plant(Entities.Bush)
move(North)
move(East)
Storage_Check()

def Hay():
while True:
for i in range(get_world_size()):
if get_water()<=0.2:
use_item(Items.Water)
if can_harvest():
harvest()
if get_ground_type() != Grounds.Grassland:
till()
move(North)
move(East)
Storage_Check()

def Carrots():
while True:
for i in range(get_world_size()):
if get_water()<=0.2:
use_item(Items.Water)
if can_harvest():
harvest()
if get_ground_type() == Grounds.Grassland:
till()
plant(Entities.Carrot)
move(North)
move(East)
Storage_Check()

def Pumpkins():
while True:
for i in range(get_world_size()):
if get_water()<=0.2:
use_item(Items.Water)
if can_harvest():
harvest()
if get_ground_type() == Grounds.Grassland:
till()
plant(Entities.Pumpkin)
move(North)
move(East)
Storage_Check()

def Reposition():
in_pos = False
while not in_pos:
if can_harvest():
harvest()
if get_pos_x()!=0:
move(West)
if get_pos_y()!=0:
move(South)
if get_pos_x()==0 and get_pos_y()==0:
in_pos = True

def Storage_Check():
if num_items(Items.Hay) < 1000:
Hay()
if num_items(Items.Wood) < 5000:
Wood()
if num_items(Items.Carrot) < 2000:
Carrots()
if num_items(Items.Pumpkin) < 9999999:
Pumpkins()


Understandably YES it DOES tell me it's due to recursion, but I feel like this is the easiest way to do things without creating a code I would have to endlessly keep adding chunks to. I know this isn't as much as a bug, and not a review, I don't know where else to mention this, but I feel like some attention must be brought to this. basically allow a form of parallel processing please? this would solve so many issues... I do understand this game is still in development but most other programming techniques are present and this is important too, albeit slightly advanced, yes...

if these were Async functions I'd simply end each function call right after the recursive call with a "return" making it not infinitely pile up.

If they indeed ARE present at a later part without my knowledge then I sincerely apologize. but it feels a bit annoying to have to rerun the function every time it freezes.

And could we have comments please? A good old CTRL+/ ?
< >
Showing 1-7 of 7 comments
umop-apisdn Dec 23, 2024 @ 9:29pm 
Tip: Use [code][/code] tags to get Steam to format your code correctly; it improves readability when we can tell where your loops/conditionals begin and end.

Reposition() Storage_Check() def Wood(): while True: for i in range(get_world_size()): if get_water()<=0.2: use_item(Items.Water) if can_harvest(): harvest() if get_pos_x()%2==0 and get_pos_y()%2==0: plant(Entities.Tree) else: plant(Entities.Bush) move(North) move(East) Storage_Check() def Hay(): while True: for i in range(get_world_size()): if get_water()<=0.2: use_item(Items.Water) if can_harvest(): harvest() if get_ground_type() != Grounds.Grassland: till() move(North) move(East) Storage_Check() def Carrots(): while True: for i in range(get_world_size()): if get_water()<=0.2: use_item(Items.Water) if can_harvest(): harvest() if get_ground_type() == Grounds.Grassland: till() plant(Entities.Carrot) move(North) move(East) Storage_Check() def Pumpkins(): while True: for i in range(get_world_size()): if get_water()<=0.2: use_item(Items.Water) if can_harvest(): harvest() if get_ground_type() == Grounds.Grassland: till() plant(Entities.Pumpkin) move(North) move(East) Storage_Check() def Reposition(): in_pos = False while not in_pos: if can_harvest(): harvest() if get_pos_x()!=0: move(West) if get_pos_y()!=0: move(South) if get_pos_x()==0 and get_pos_y()==0: in_pos = True def Storage_Check(): if num_items(Items.Hay) < 1000: Hay() if num_items(Items.Wood) < 5000: Wood() if num_items(Items.Carrot) < 2000: Carrots() if num_items(Items.Pumpkin) < 9999999: Pumpkins()

Originally posted by YourOnlyEnd:
And could we have comments please? A good old CTRL+/ ?
Try the old standby, the pound sign (or hashtag, for you youngins): "#"
YourOnlyEnd Dec 24, 2024 @ 5:10am 
ooh thanks for the advice!
but yea... the issue is with the Infinite recursion...
samite_alchemist Dec 24, 2024 @ 9:07am 
Wouldn't it be better to put the Storage Check in Main? Just seems better to have Main call the subroutines to harvest the resources.
umop-apisdn Dec 24, 2024 @ 4:22pm 
Perhaps you can eliminate the recursion. Have you considered moving the call to StorageCheck() to its own loop, in main? That is, remove it from each of the product loops.

Something like...
Reposition() while true: StorageCheck() def Wood(): for column in range(get_world_size(): for row in range(get_world_size()): if get_water() <= 0.2: use_item(Items.Water) if can_harvest(): harvest() if get_pos_x()%2==0 and get_pos_y()%2==0: plant(Entities.Tree) else: plant(Entities.Bush) move(North) move(East) def Hay():...
Last edited by umop-apisdn; Dec 24, 2024 @ 4:23pm
YourOnlyEnd Dec 26, 2024 @ 3:34am 
oh that's such a good idea.... why did I not think of that..
Last edited by YourOnlyEnd; Dec 26, 2024 @ 4:58am
rawj_87 Dec 28, 2024 @ 1:01pm 
Personally i did a storage check as well

def Check():
Number1=500000
Number2=200000
Number3=100000
Number4=90000
Number5=80000
Number6=70000
Number7=60000
Number8=1000

if num_items(Items.Power) <Number8 :
Flower()
elif num_items(Items.Hay) < Number1:
Hay()
elif num_items(Items.Wood) < Number2:
Tree()
elif num_items(Items.Carrot) < Number3:
Carrot()
elif num_items(Items.Pumpkin) < Number4:
Pumpkin()
elif num_items(Items.Cactus) < Number5:
Cactus()
elif num_items(Items.Gold) < Number6:
Maze()
elif num_items(Items.Bone) < Number7:
Dino()
else:
do_a_flip()

then added


Number=0
while True:
if Number>=10:
Check()
Number=0

Number=Number+1

to each of the codes then only checks every 10 runs of the code. i set it based off what i am farming.. the numbers above are just examples
Last edited by rawj_87; Dec 28, 2024 @ 1:03pm
YourOnlyEnd Dec 28, 2024 @ 4:07pm 
I respect your approach, what I tried doing was a complete and passive automation, I managed to figure it out thanks to umop's recommendation, but yea, becomes I sometimes would run halfway through a cycle and it'd get on my nerves
Last edited by YourOnlyEnd; Dec 28, 2024 @ 4:08pm
< >
Showing 1-7 of 7 comments
Per page: 1530 50