I am trying to make a "magical" bush...basically a bush that regrows berries every 30 seconds.
I have this code so far:
obj/proc/FillBerries()
if(!src.Berries)
new/obj/Berries(src.loc)
src.Berries = 1
sleep(300)
FillBerries()
obj
var
Berries
obj
Berries
icon = 'Foliage.dmi'
icon_state = "Berries"
verb
Take_Berries()
set src in oview(1)
set category = "Other"
for(var/obj/Foliage/BerryBush/B in view(0))
B.Berries = 0
usr<<"You grab some berries!"
Move(usr)
Foliage
BerryBush
icon = 'Foliage.dmi'
icon_state = "B1"
density = 1
Berries = 1
New()
..()
FillBerries()
Now because of lag in the coding, it allows people to pick the same "berries" twice.
But more annoying is that the berries never come back!
Any help would be greatly appreciated!
~GokuSS4Neo~
This is called recursion, and what happens is that the "old" run of the proc is put on hold to wait for the result of the new call. Get enough procs on hold like that and you get a stack overflow.
There are only two correct ways to do this: Use a while() loop, or use spawn() to call the proc again.
However, this loop is a bad idea in this case anyway; it won't regenerate the berries 30 seconds after they're picked, but rather every 30 seconds from an arbitrary point.
As an alternative to the FillBerries() loop, I suggest instead you simply call a proc instaed of setting B.Berries=0:
I don't know why the berries would stop refilling after a double-pick, but whatever the reason, it should be fixable now.
Lummox JR