ID:155600
 
Sorry for posting this often, but I need some help.
I'm making an object, which, when created, spawns 4 other objects in 4 directions and passes them value, which is random between 5 and 10, minus one, or sometimes two. Then that new object creates another 4 objects and passes it's value minus one or two again. New object doesn't make another object if it's value is one. That way I'm trying to make mountains with random forms.
The problem is, the value is passed wrong, so it only shows up good when it sends it as message, but it's true value is 0. For example, after 3 generations of objects are made, initial one returns 7, another one 6 and third on -1.
Another thing is, I was forced into using different objects for different generations. When 2nd generation object tries to make another 2nd, i get loads of spam. If it tries to make 3rd, which is identical to 2nd, everything works fine
And last, I have a question. What would be best way to check if, for example, neighbor turf is /turf/cliff

My lame code:
atom
high
icon='turf.dmi'
var/H
New()
var/H=rand(5,10)
if(H!=0)
var/atom/high2/N= new/atom/high2(locate(src.x+1,src.y,1))
var/atom/high2/S= new/atom/high2(locate(src.x-1,src.y,1))
var/atom/high2/E= new/atom/high2(locate(src.x,src.y+1,1))
var/atom/high2/W= new/atom/high2(locate(src.x,src.y-1,1))
N.H=H-prob(10)-1
S.H=H-prob(10)-1
E.H=H-prob(10)-1
W.H=H-prob(10)-1



high2
icon='turf.dmi'
var/H
New()
world<<"Made a spawn"
if(H!=0)
world<<"continue"

var/atom/high3/N= new/atom/high3(locate(src.x+1,src.y,1))
var/atom/high3/S= new/atom/high3(locate(src.x-1,src.y,1))
var/atom/high3/E= new/atom/high3(locate(src.x,src.y+1,1))
var/atom/high3/W= new/atom/high3(locate(src.x,src.y-1,1))
N.H=H-prob(10)-1
S.H=H-prob(10)-1
E.H=H-prob(10)-1
W.H=H-prob(10)-1
Click()
usr<<"[H]"


high3//for testing
icon='turf.dmi'
var/H
Click()
usr<<"[H]"
New()
if(H!=0)
var/atom/high4/S= new/atom/high4(locate(src.x-1,src.y,1))


high4//for testing
var/H
Well, at least I managed to make them to display wrong vars corretly. After reading a little about atoms in reference, tried to change them into turfs, but that didn't help either.
In response to Martys1103
The problem you're running into is the order in which your code executes: the New() process is called right after new() creates an instance of the atom, so H hasn't been set yet.

The reason you were getting spam when just using the high2 atom was that you had created an infinite loop. You didn't initialize H, so it defaults to null. Because H isn't set by the time New() is called, H!=0 evaluates as true (null!=0). Because of this, each time high2/New() is run, it will always create more copies, that will create more copies, that will create more copies, ect.

Your best option is likely to pass the H variable through new() to New().

The syntax is as simple as tacking on another parameter after the location:
new/atom/high3(locate(src.x+1,src.y,1), H-rand(1,2))


Then you can access that passed value in New() by adding an argument (but in atoms, the first is always reserved for the loc):
atom/high3/New(loc,setH)
H = setH
if(H>0)
// ...


I would also suggest using H>0 as your conditional, as it's more robust (otherwise, if H somehow becomes negative [and right now there's a 50-50 chance it will], you'll get into another infinite loop)

I would also suggest using the turf type instead of the atom type, unless you have some specific reason for doing otherwise.
In response to DarkCampainger
Thank you, everything works fine. It was very helpful and I learned a bit. But there is one more question. I tried to put on a little delay so it wouldn't make program not responding and I noticed strange behavior.
First is with sleep. Initial turf spawns one "pole" to the north, which then starts spreading to the sides. Then initial tile starts expanding south and to the sides. It happens very slowly. If I use spawn(), Game lags before and after generating, while sleep() doesn't. Is it because how new() behaves?