ID:139566
 
Code:
proc
PlaceSeeds()
var/maxX = world.maxx
var/maxY = world.maxy
var/list/turf/Turfs = list()
var/list/turf/SeedTurfs
var/Seeds = ((maxX*maxY)/200)+1 //0.5% of the world are seeds, with a minimum of 1
Seeds = round(Seeds) //round to the nearest whole number

for(var/turf/T in world)
Turfs += list(T)
for(var/I = 0, I < Seeds, I++)
var/turf/CurT = pick(Turfs)
SeedTurfs += list(CurT)
Turfs -= list(CurT)
world << "RAWR"
for(var/turf/T in SeedTurfs)
T = new /turf/grass/


Problem description:

runtime error: bad loc proc name: PlaceSeeds (/proc/PlaceSeeds) source file: WorldGeneration.dm,47 usr: Guest-1484714420 (/mob) src: null call stack: PlaceSeeds() Guest-1484714420 (/mob): Test/Debug PlaceSeeds Proc() RAWR

What its suppose to do:

Get a list of turfs in the world, randomly choose a bunch of them (0.5% of the world total turfs, minimum 1) and replace that turf with a /turf/grass. It seems to try to make a new turf before a previous turf has been gained, leading to a bad location, which doesnt make sense as the code to choose a proc is ABOVE where the error takes place (the creation of the new turf seems to be superseding the rest of the code for some reason -.-)

I've tried a number of things to make this work (Including making a new proc who's soul purpose was to replace it) but all end up with bad locations, even though the location DOES exists. I also tried using random X and Y co-ordinates (using var/X = rand(1, world.maxx) and var/Y =rand(world.maxy)) and making the new turf like var/turf/T = new(X,Y,1) but this didnt work either and gave a bad loc


edit: Solved this.. but still wondering why the above method wouldnt work o.O
To create a new turf, you must pass the turf it is to replace as the first argument to new().