ID:834347
 
so Im writing a program with a semi-random terrain generator. so the code has some dice rolls, and every generator within range of a desertgen has a chance of becoming one of 6 different desert terrain pieces. however, nothing happens and it gives me an error message.

area
generator
desertgen
icon = 'desertdirt.dmi'
verb
generate()
set src in orange(10)
var
A = "1d6"
B = roll(A)
C = roll(A)
for(var/area/generator/M in orange(10,src))
if(B >= 4)
new /turf/desert/desertdirt(M.loc)
else if(B == 3)
new /turf/desert/sandunes(M.loc)
else if(B == 2)
if(C >= 4)
new /turf/desert/desertberries(M.loc)
else if(C <= 3)
new /turf/desert/oasis(M.loc)
else if(B == 1)
if(C >= 4)
new /turf/desert/desertcliffs(M.loc)
else if(C <= 3)
new /turf/desert/prairie(M.loc)
new /turf/desert/desertdirt(src)

that code gives me this error:
runtime error: bad loc
proc name: generate (/area/desertgen/verb/generate)
usr: Guest-1382472848 (/mob)
src: the desertgen (/area/desertgen)
call stack:
the desertgen (/area/desertgen): generate()

I don't know what Im doing wrong. the code compiles fine.
thank you for your help.
Please use <dm></dm> tags.
I know this sounds really stupid, but what are those?
Encase your code with <dm> and </dm>. It will preserve the whitespace so we can actually read your code.
ok thanks

area
generator
desertgen
icon = 'desertdirt.dmi'
verb
generate()
set src in orange(10)
var
A = "1d6"
B = roll(A)
C = roll(A)
for(var/area/generator/M in orange(10,src))
if(B >= 4)
new /turf/desert/desertdirt(M.loc)
else if(B == 3)
new /turf/desert/sandunes(M.loc)
else if(B == 2)
if(C >= 4)
new /turf/desert/desertberries(M.loc)
else if(C <= 3)
new /turf/desert/oasis(M.loc)
else if(B == 1)
if(C >= 4)
new /turf/desert/desertcliffs(M.loc)
else if(C <= 3)
new /turf/desert/prairie(M.loc)
new /turf/desert/desertdirt(src)
Areas don't have a location, so M.loc is returning null, which isn't a valid location for a turf.

An area is actually collection of turfs, so to get all of the turfs that an area covers, you just need to loop through its contents list.

Areas placed in the map editor actually only have a single instance per type, so you may want to rethink your design. I would offer some suggestions, but it's not clear how you want it to work.

Also, you aren't re-rolling your random values for each tile, which means they'll all be the same.
okay, I switched the areas out for turfs and it runs fine. I also made it re-roll. thanks for the advice