ID:178598
 
here's the code I have for random placement and the interpreter sez it has no errors.

PickLoc(atom/movable/M)
var/list/picklist = list()
for(var/turf/T in world)
if(T.density) continue
picklist += T
M.loc = pick(picklist)
return

But when I run it it sez runtime error :P:

runtime error: Cannot modify null.loc.
proc name: PickLoc (/mob/proc/PickLoc)
usr: Likwiddraino000 (/mob/player)
src: Kiwi (/mob/npc/Kiwi)
call stack:
Kiwi (/mob/npc/Kiwi): PickLoc(null)
Kiwi (/mob/npc/Kiwi): Death(null)
Likwiddraino000 (/mob/player): Attack(Kiwi (/mob/npc/Kiwi))
First, you need to change the line I've bolded back one indention (which I've done here):
PickLoc(atom/movable/M)
var/list/picklist = list()
for(var/turf/T in world)
if(T.density) continue
picklist += T
M.loc = pick(picklist)
return

Kiwi (/mob/npc/Kiwi): PickLoc(null)
This means you're not passing a mob to PickLoc(), which means it gets to that bolded line, sees M.loc but it has no M, hence the null.loc error.

-AbyssDragon
In response to AbyssDragon
:(
In response to Likwiddraino000
How are you calling PickLoc()? Unless you changed that, its still going to get called with no M, which is what's really causing your problem. (The indention mistake was unrelated to this one, but it would cause problems later).

It looks like you're just calling PickLoc(), when you need to be passing some mob to it. I'm not sure exactly what you're doing with it, so it could be anything. Its probably src or usr, however.

-AbyssDragon
In response to AbyssDragon
proc
Death(mob/M)
if(src.type == /mob/player)
PCDeath()
else
if(src.HP <= 0)
usr.exp += src.exp_give
view() << "The enemy died!"
view() << "You get [src.exp_give] experience!"
PickLoc()
In response to Likwiddraino000
Likwiddraino000 wrote:
proc
Death(mob/M)
if(src.type == /mob/player)
PCDeath()
else
if(src.HP <= 0)
usr.exp += src.exp_give
view() << "The enemy died!"
view() << "You get [src.exp_give] experience!"
PickLoc()

AbyssDragon is correct. The last line here should probably be PickLoc(src) or PickLoc(M). I'm guessing src since you aren't using M in this definition of Death(). You need to pass an argument into PickLoc().
In response to ACWraith
ok the code no longer has run-time errors...but the code doesn't randomly place them anywhere, it just deletes them :P

if(src.HP <= 0)
usr.exp += src.exp_give
view() << "The enemy died!"
view() << "You get [src.exp_give] experience!"
PickLoc(src)


PickLoc(atom/movable/src)
var/list/picklist = list()
for(var/turf/T in world)
if(T.density) continue
picklist += T
src.loc = pick(picklist)
return
In response to Likwiddraino000