ID:264232
 
Code:
mob
var{firing=0;move1=1;damage=0}

obj
var{mob/owner=0;total=0;moved=0;list/Beam=list()}
Beams
icon = 'Beam.dmi'
density = 1
restricted = 0
pixel_step_size = 12
animate_movement=SYNC_STEPS
Head
icon_state = "head"
New()
spawn(1)
Start()
Check()
..()
proc
Start()
walk(src,owner.dir,1)//notice how i took usr out here
Check()
while(src)
var/turf/T = get_step(src,src.dir)
if(!T)
owner.firing = 0
owner.icon_state = ""
owner.move1 = 1
if(src)
for(var/obj/O in src.Beam)
del(O)
del(src)
sleep(1)


Bump(atom/M)
if(isturf(M))
owner.firing = 0
owner.icon_state = ""
owner.move1 = 1
for(var/obj/O in src.Beam)
del(O)
del(src)
else if(ismob(M))
var/mob/Target = M
view(src.owner) << "[src.owner]'s beam hits [M] for [owner.damage]!"
Target.PL -= owner.damage
Target.PowerlevelCheck()
owner << "Target's powerlevel is [Target.PL]."
owner.firing = 0
src.owner.icon_state = ""
owner.move1 = 1
for(var/obj/X in src.Beam)
del(X)
del(src)
else if(isobj(M))
if(istype(M,/obj/Beams/Head))
var/obj/O = M
src.restricted = 1
src.Struggle(O) // get the struggle effect
if(src.owner.damage>O.owner.damage)
var/mob/loser = O.owner
for(var/obj/X in O.Beam)
del(X)
del(O)
walk_towards(src,loser,3)
else
if(!ismob(M) && !isturf(M) && !isobj(M) && !isarea(M))
owner.firing = 0
owner.icon_state = ""
owner.move1 = 1
for(var/obj/O in src.Beam)
del(O)
del(src)

Body
icon_state = "body"
density = 1
Move()
if(restricted) return
if(istype(src,/obj/Beams/Head))
var/obj/Body = new/obj/Beams/Body(src.loc)
Body.owner = src
src.Beam.Add(Body)
Body.dir = src.dir
moved++
if(moved == total)
owner.firing = 0
owner.icon_state = ""
owner.move1 = 1
if(src)
for(var/obj/O in src.Beam)
del(O)
del(src)
..()

obj/proc/Struggle(obj/M)
src.restricted = 1
var/a = 3 //adjust this to how many times you want the struggle "effect" to last
while(a)
a--
var/obj/O = src.Beam[src.Beam.len]
del(O)
sleep(2)
src.x--
step(M,M.dir)
var/obj/B = M.Beam[M.Beam.len]
del(B)
sleep(2)
M.x++
src.restricted = 0
step(src,src.dir)

obj/var/restricted = 0

mob
proc
KBeam()
var/obj/Head = new/obj/Beams/Head()
if(usr.dir == NORTH)
Head.loc = locate(usr.x,usr.y+1,usr.z)
if(usr.dir == SOUTH)
Head.loc = locate(usr.x,usr.y-1,usr.z)
if(usr.dir == WEST)
Head.loc = locate(usr.x-1,usr.y,usr.z)
if(usr.dir == EAST)
Head.loc = locate(usr.x+1,usr.y,usr.z)
Head.total = 10
Head.dir = usr.dir
Head.owner = usr
mob
verb
KameHameHa()
if(usr.firing)
usr << "This cannot be done."
return
else
usr.firing = 1
usr.move1 = 0
usr.damage=5


Problem description:
When my two beams collide with eachother, it does the struggle effect, but I get these runtimes.


runtime error: Cannot read null.dir
proc name: Struggle (/obj/proc/Struggle)
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Struggle(null)
Head (/obj/Beams/Head): Bump(null)

runtime error: Cannot read null.owner
proc name: Bump (/obj/Beams/Head/Bump)
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Bump(null)

runtime error: Cannot read null.x
proc name: Struggle (/obj/proc/Struggle)
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Struggle(null)
Head (/obj/Beams/Head): Bump(null)

runtime error: Cannot read null.owner
proc name: Bump (/obj/Beams/Head/Bump)
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Bump(null)
Put this in your code:
#define DEBUG

It will let the runtime errors tell you the exact line number that the problem is happening in your code file. Reply with them if you want help, because I'm no reading through it all.
In response to Kaiochao
Ahh, Thanks, I didn't know about #define debug.

runtime error: Cannot read null.dir
proc name: Struggle (/obj/proc/Struggle)
source file: techniques.dm,108
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Struggle(null)
Head (/obj/Beams/Head): Bump(null)
Line 108       step(M,M.dir)

runtime error: Cannot read null.owner
proc name: Bump (/obj/Beams/Head/Bump)
source file: techniques.dm,63
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Bump(null)
Line 63                       if(src.owner.damage>O.owner.damage)

In response to Dranzer_Solo
Of course, anyone could read those lines and see nothing is wrong with them. Providing the surrounding lines or preferably the whole procedure those lines are under would help.
In response to Kaiochao
Pardon? I gave you the whole code, then I narrowed down the runtime error lines, what do you want now?
In response to Dranzer_Solo
In one post, the whole code. In another one, the individual lines. I wasn't going to go through all your code for those two lines, but I had time.

Apparently M and O don't exist at the time you're using them.

Problem 2.
            Bump(atom/M)
//...
else if(isobj(M))
if(istype(M,/obj/Beams/Head))
var/obj/O = M
src.restricted = 1
src.Struggle(O) // get the struggle effect
if(src.owner.damage>O.owner.damage) //Problem line 2. O doesn't exist anymore because something deleted it.
var/mob/loser = O.owner
for(var/obj/X in O.Beam)
del(X)
del(O)
walk_towards(src,loser,3)


Problem 1.
obj/proc/Struggle(obj/M)
src.restricted = 1
var/a = 3 //adjust this to how many times you want the struggle "effect" to last
while(a)
a--
var/obj/O = src.Beam[src.Beam.len]
del(O)
sleep(2)
src.x--
step(M,M.dir) //Problem line 1. Same as problem line 2, M doesn't exist anymore because something deleted it.
var/obj/B = M.Beam[M.Beam.len]
del(B)
sleep(2)
M.x++
src.restricted = 0
step(src,src.dir)


The fix:
            proc
Start()
walk(src,owner.dir,1)//notice how i took usr out here
//off topic, but usr shouldn't have had to be there in the first place.
Check()
while(src)
var/turf/T = get_step(src,src.dir)
if(!T)
owner.firing = 0
owner.icon_state = ""
owner.move1 = 1
if(src)
for(var/obj/O in src.Beam)
del(O)
del(src) //This bit of code is causing the head to be deleted, nullifying the references to Struggle() and Bump().
//Bump() gets called after this, so the beam head is gone already by the time Bump() and Struggle() are called.
//Bump() is called when the beam bumps into something. This proc checks for obstacles before the beam bumps anything, because it is checking for obstacles already ahead of it.
sleep(1)


Bump(atom/M) //Bump declaration from the top.
In response to Kaiochao
Oh, I'm sorry, I'll post more of the code and runtime info in the furtue, thanks, I'll read over your help for me when I get home from work, thanks alot, I'll post if I run into any problems.




In response to Dranzer_Solo
Ok, so I need to check before Bump is called, but how would I go about that?
        Head
icon_state = "head"
New()
spawn(1)
Start()
Check()
..()


So instead of calling Check() here, should I be calling it in Bump() ?
In response to Dranzer_Solo
I hate bumping, but if anyone could help me out that be great..
In response to Dranzer_Solo
Anyone?
No usr in procs.

Also add safety checks. Like if(src) on the Struggle().

It checks if src is still valid before trying to access any of it's variables.
In response to Andre-g1
Yea but how can I make it call Struggle before bump() so I am not getting these errors.
I think the problem lies in your struggle() proc. For one, you're only restricting the src head, not M, so M could still move and bump your head object causing two struggles for every encounter. Also, altering src.x isn't moving the head anywhere. You need to set it's loc variable to a turf, or use Move(). Setting the x,y or z variable directly can have unwanted consequences, like making the location null.