ID:269685
 
I am trying to make it so that the lava spreads and keeps spreading. this is the code i have come up with:

mob
icon = 'icon.dmi'
icon_state = "mob"
obj/lava
icon = 'icon.dmi'
icon_state = "lava"
proc
Flow(turf/Flamable/M)
sleep(5)
for(var/turf/T in oview(1, src))
var/obj/lava/G = new
G.loc = T
New()
src.Flow(src.loc)
..()
turf/var/flamable
turf/Flamable
grass
icon = 'icon.dmi'
icon_state = "grass"

Though whenever I run this only 9 lava get created. That is the starting lava in the middle and 8 others surrounding it. Could someone help me.
I think this could have something to do with the New() command.
That's because when you first create the new lava object, its location is null, so it's trying to spread from null. Then, after it tries to spread, you set its location.

Your use of sleep(5) doesn't fix this either, because "G.loc = T" won't get executed until the lava's New() proc returns. And New() won't return until Flow() returns - but Flow() won't return for half a second, because it's asleep. =) So by the time "G.loc = T" is executed, Flow() has already happened.

To fix this, spawn() off src.Flow() from New() so that New() gets to return immediately. Using spawn() is usually a good idea when the proc that New() calls will call sleep().

    New()
spawn() src.Flow(src.loc)
..()


Once you do that, it should work.

Another tip: You can specify an initial location for New() by passing it to new:

var/obj/lava/G = new(T)


Then you don't need "G.loc = T".

One final warning: Your code will spread lava into areas that are already covered with lava. If you wait long enough, you will run out of objects and get an error message, and new objects will no longer be created. (You can only have 65536 /obj objects in the world at once.) To avoid this, you should check to see if lava exists in a tile before you create more lava there.
In response to Crispy
It works too well. When I use it it slows up my computer.
This is the new code:
obj/lava
icon = 'icon.dmi'
icon_state = "lava"
proc
Spread(turf/Flamable/grass/M,obj/lava/L)
sleep(5)
for(var/turf/T in oview(5, src))
if(T.flamable && L == null)
var/obj/lava/G = new
G.loc = T
New()
spawn() src.Spread(src.loc)
..()

Would my L == null be working.
In response to Crispy
Crispy wrote:
That's because when you first create the new lava object, its location is null, so it's trying to spread from null. Then, after it tries to spread, you set its location.

He could have saved himself a lot of grief if he'd just paid attention the first time. ([link])

Lummox JR
In response to ADT_CLONE
What on earth are you trying to do? Of course L will always be null, because you're never giving it a value.
In response to Crispy
Well the fact is its going really slow. It works though it goes so slow that It takes 10 seconds to move one tile.
In response to ADT_CLONE
Spawning lots and lots of objects will do that. =)

I suggest you slow down the spawn rate, and make it so that multiple lava objects don't get created on the same tile.
In response to ADT_CLONE
ADT_CLONE wrote:
I think this could have something to do with the New() command.

New() isn't a command but a proc :).

O-matic