ID:147501
 
EDIT: Fixed it. Now I just have to figure out how to make it less CPU intensive, and work on all the turfs around it equally. Incidentally, anyone have any ideas for that? At the moment, it just loops through the turfs and finishes them. How would I get it to do all of them "at once" by dividing up the amount of water sent each way? It would be a ninth each, but some of them don't need flowing too, and some of them don't need as much water to "fill" as the rest of them.

This code is causing me some problems. The idea is to create rivers that can make themselves at runtime, and this particular example should end up with the entire world being full of water. However, it seems like water is vanishing somehow. The flow() procedure for the spring is being called every half a second, like it should, but it's waterlevel is always the same. It is always two. It spreads out to one turf on the map that has an altitude of zero, and ends up with a waterlevel of three. Nothing happens after that. The game doesn't lock, the waterlevel just doesn't change. Whats going on?

turf
icon='turf.dmi'
var/altitude=0
var/waterlevel=0
proc/Flow()
set background=1
for(var/turf/t2 in range(1,src))
if((t2.altitude+t2.waterlevel)<(altitude+waterlevel))
while((t2.altitude+t2.waterlevel)<(altitude+waterlevel))
t2.waterlevel++
waterlevel--
if(waterlevel<=0) break
spawn(5) t2.Flow()
if(waterlevel>0) icon_state="water"
else icon_state=initial(icon_state)
verb/Check()
set src in world
usr << "Altitude:[altitude], Waterlevel:[waterlevel]"
grass
icon_state="grass"
spring
icon_state="water"
waterlevel=2
New()
..()
spawn(5) Flow()
Flow()
..()
waterlevel+=2
spawn(5) Flow()

EDIT:
Adding this code:
t2.overlays+=image('turf.dmi',t2,"water")

Makes it work properly for some reason. I don't even have to output the image. It's added under the start of the For() loop.
What if the waterlevel of one turf is plus one of a surrounding turf. When it "flows", one will be added to the new turf while one is subtracted from the source. The next time flow is processed, the waterlevel is just going to be sent back and forth and back and forth until.. forever?

-Kosh