ID:142718
 
<b>Code:</b>
<dm>
lizard_javelin
icon = 'base.dmi'
icon_state = "lizard javelin"
hp = 100
def = 0
var/t = 0
New()
spawn for()
for(var/mob/enemy/M in oview(7))
if(M)
var/obj/javelin/J = new
J.loc=src.loc
spawn for()
step_towards(J,M)
sleep(1)
step_towards(J,M)
sleep(1)
step_towards(J,M)
if(!M)
del J
break
if(M.loc==J.loc)
del J
M.hp -= 20
sleep(2)
if(!M)
return
sleep(40)


Problem description:
well whenever j hits M I get this error.
Sun Mar 23 10:58:40 2008
World opened on network port 5774.
Welcome BYOND! (4.0 Beta Version 412.977)
Stopped server.
World opened on network port 5774.
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1650
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (14,37,1) (/turf))
runtime error: Cannot read null.hp
proc name: New (/mob/priest/New)
source file: Protection.dm,1670
usr: the mpriest (/mob/priest/mpriest)
src: the mpriest (/mob/priest/mpriest)
call stack:
the mpriest (/mob/priest/mpriest): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.hp
proc name: New (/mob/priest/New)
source file: Protection.dm,1670
usr: the mpriest (/mob/priest/mpriest)
src: the mpriest (/mob/priest/mpriest)
call stack:
the mpriest (/mob/priest/mpriest): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.hp
proc name: New (/mob/priest/New)
source file: Protection.dm,1670
usr: the mpriest (/mob/priest/mpriest)
src: the mpriest (/mob/priest/mpriest)
call stack:
the mpriest (/mob/priest/mpriest): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.hp
proc name: New (/mob/priest/New)
source file: Protection.dm,1670
usr: the mpriest (/mob/priest/mpriest)
src: the mpriest (/mob/priest/mpriest)
call stack:
the mpriest (/mob/priest/mpriest): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/great_trident/New)
source file: Protection.dm,1715
usr: the mgreat trident (/mob/great_trident/mgreat_trident)
src: the mgreat trident (/mob/great_trident/mgreat_trident)
call stack:
the mgreat trident (/mob/great_trident/mgreat_trident): New(the grass (25,34,1) (/turf/grass))
Rebooted server.
Stopped server.
World opened on network port 5774.
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649
usr: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
src: the mlizard javelin (/mob/lizard_javelin/mlizard_javelin)
call stack:
the mlizard javelin (/mob/lizard_javelin/mlizard_javelin): New(the turf (25,37,1) (/turf))
runtime error: Cannot read null.loc
proc name: New (/mob/lizard_javelin/New)
source file: Protection.dm,1649

It would be very helpful if you could find what is wrong.

do you have it like this?
mob
lizard_javelin
icon = 'base.dmi'
icon_state = "lizard javelin"
hp = 100
def = 0


with "mob"? You probably do but you didnt show it in the coding. Not sure if i helped lol I think that might be it cuz it says cannot read null hp, def etc
In response to Deity Production 08
its like that...
in the runtime error it comes up to this line....
" if(M.loc==J.loc)"
Oh i just noticed this

New (/mob/lizard_javelin/New)

the new() is lower case, im not sure wehat youre doing with the /New) though...
In response to Deity Production 08
well its suppose to be like that and that is the entire problem where is calling new twice or something like that.
In response to Nategrant
whats the purpose of calling it a second time? and you shouldnt have spaces anywhere in coding unless its in quotation marks.
You have New (/mob...
should be new(/mob...
In response to Deity Production 08
well since I have "New" are you going to tell me in the code what I should change?
In response to Deity Production 08
object.New() is a procedure called when an object is created.

new /object/path(argument) is used to create an object and send arguments, if any
In response to GhostAnime
could you tell me what is wrong then?
You should be calling the parent whenever you override a proc (unless if you're sure you don't want to). So, put ..() as the first line of New()

            spawn for()


Using for() to create an infinite loop is not a good idea. while() is generally a better idea:

spawn() while(TRUE)


Also, putting parenthesis around spawn() is also good practice, though the spawn() isn't actually needed here at all: the new directive creates a new thread by default.

                for(var/mob/enemy/M in oview(7))


That oview(7) should be oview(7,src). While usr is technically set in mob/New(), it's poor programming practice to use it for anything outside verbs or verb-like procs.

                    if(M)
...
if(!M)
return


These lines are entirely meaningless. Just remove them.

                        var/obj/javelin/J = new
J.loc=src.loc


This is okay... but you should instead be doing:

var/obj/javelin/J = new(src.loc)


And now, we have to deal with this whole inner loop all at once:

                        spawn for()
step_towards(J,M)
sleep(1)
step_towards(J,M)
sleep(1)
step_towards(J,M)
if(!M)
del J
break
if(M.loc==J.loc)
del J
M.hp -= 20
sleep(2)


The use of break to break a loop instead of properly using the conditional in loops is going to create spaghetti code. So, one of your problems is in the second if() statement, where J is being deleted, but the loop is not stopped, and so the second if() statement is reached again (step_towards() won't cause an error with null arguments), and when you try to read J.loc, you get an error because J is null.

However, that's no the only problem: every time you sleep(), you give an opportunity for the status of everything to change. A loop like this should look something like:

while(projectile && target)
step_towards(projectile, target)
if(projectile.loc == target.loc)
cause damage
sleep(speed)
del(projectile)


Of course, considering how this projectile can't miss or be outrun, I don't know why you don't just use missile() and instantly cause the damage. It wouldn't be hard to add another condition to limit the range (define a variable range as being, say, 7. Include it in the condition of the while(), and subtract 1 from it each loop).

Another problem: you're reducing M's hp, but never calling deathcheck().

Aside from all these problems, this whole thing should be moved into its own proc. It makes things easier to profile and allows you more flexibility.

Oh, and you are only showing what's causing half of your errors. You haven't shown us mpriest.
In response to Garthor
I have followed your advice and it works, Thank you. I didn't supply the mspore code because it is the same the a javelin.
Also not that i do it this way it only sends one "J" is there a way to send like 2 or 3?
In response to Garthor
Hello.

Garthor wrote:
Using for() to create an infinite loop is not a good idea.

Yes it is.
Well, the point isn't even worth mentioning since he already used it properly, but should have used a conditional loop regardless.

the spawn() isn't actually needed here at all: the new directive creates a new thread by default.

What? Who? Where?
In response to Kaioken
Kaioken wrote:
Hello.

Garthor wrote:
Using for() to create an infinite loop is not a good idea.

Yes it is.
Well, the point isn't even worth mentioning since he already used it properly, but should have used a conditional loop regardless.

I find for() to be considerably less clear than while(TRUE).

the spawn() isn't actually needed here at all: the new directive creates a new thread by default.

What? Who? Where?

My mistake, I was thinking of something else entirely.