ID:1997952
 
(See the best response by Rushnut.)
Code:
Turns

proc
Turn(mob/Opponent)
var/mob/L = usr.Target
if((usr.Speed + usr.Speed_Mod) > (L.Speed + L.Speed_Mod))
usr << "Its your turn!"
usr.Choose()

if((usr.Speed + usr.Speed_Mod) < (L.Speed + L.Speed_Mod))
usr << "Its [L] turn!"
L.Turn = 1
L.EChoose()

else
usr << "Its [L] turn!"
L.Turn = 1
L.EChoose()


Problem description:
I get this error...

runtime error: Cannot read null.Speed
proc name: Turn (/Turns/proc/Turn)
source file: Datums.dm,17
usr: Julian (/mob/Player)
src: /Turns (/Turns)
usr.loc: Weed (32,47,1) (/turf/Weed)
call stack:
/Turns (/Turns): Turn(null)
Weed (32,47,1) (/turf/Weed): Entered(Julian (/mob/Player), Weed (31,47,1) (/turf/Weed))
It must be reading L to be null. The problem with the code likely isn't here, but rather you should make sure you're setting usr.Target beforehand.
turf
Weed
icon='Turfs.dmi'
icon_state= "Weed"
Entered(mob/M)
if(prob(30))
var/mob/P = new /mob/Enemy/Shade
M.lastx = M.x
M.lasty = M.y
M.lastz = M.z
M.isfrozen = 0
M.loc = locate(M.x,M.y,4)
M.dir = EAST
P.loc=locate(M.x+1,M.y,M.z)
P.dir = WEST
M << "Lvl : [P.Level] [P] appeared! Get ready for battle!"
M.Target = P
P.Target = M
M.turn.Turn()


Thats where it starts
I'd assume you'd get an error from the line var/mob/L = usr.Target at compile time, so I'm confused why this works at all, but I digress.

The problem is that you're using usr in a proc. I'm not 100% sure on the syntax for your code, but here's a few things I noticed

1: You're defining an Opponent var, but then not actually using it anywhere
2: You're using usr in the proc, which isn't going to work how you expect
3: You don't set the first player's turn to 1, which I assume will break things later on
4: Your if/if/else branch won't work how I assume you intend, here's what'll happen

if my speed is faster than enemies speed, say it's my turn, then take my turn
if enemies speed is faster than my speed, say it's enemies turn, then take enemies turn
else say it's enemies turn, then take enemies turn

Here's a quick and nasty fix, which might not work with your code, but you can study to try and learn where you went wrong.
Turns

proc
Turn(mob/Player,mob/Opponent)
if((Player.Speed + Player.Speed_Mod) > (Opponent.Speed + Opponent.Speed_Mod))
Player << "Its your turn!"
Player.Turn = 1
Player.Choose()
else
Player << "Its [L] turn!"
Opponent.Turn = 1
Opponent.EChoose()


Then you can simply do 'Turn(M,P)'.

Good luck!
turf
Weed
icon='Turfs.dmi'
icon_state= "Weed"
Entered(mob/Player/M)
if(M.Hit_Points <= 0)
return
if(prob(30))
var/mob/P = new /mob/Enemy/Shade
M.lastx = M.x
M.lasty = M.y
M.lastz = M.z
M.isfrozen = 0
M.loc = locate(M.x,M.y,4)
M.dir = EAST
P.loc=locate(M.x+1,M.y,M.z)
P.dir = WEST
M << "Lvl : [P.Level] [P] appeared! Get ready for battle!"
M.Target = P
P.Target = M
Turn(M,P)

I don't see anything wrong here.. I Changed it to this way.

proc
Turn(mob/Player,mob/Opponent)
if((Player.Speed + Player.Speed_Mod) >= (Opponent.Speed + Opponent.Speed_Mod))
Player << "Its your turn!"
Player.Choose()

if((Player.Speed + Player.Speed_Mod) <= (Opponent.Speed + Opponent.Speed_Mod))
Player << "Its [Opponent] turn!"
Opponent.EChoose()

else
Player << "Its [Opponent] turn!"
Opponent.EChoose()

And I changed this just to a proc and still had the same outcome.
Are you accidentally deleting P somewhere? I can't see anything that should be causing that error in the above code.
proc
DeathCheck(mob/Attacker,mob/Defender)
if(Defender.Hit_Points <= 0)
if(istype(Attacker,/mob/Player))
Attacker << "[Defender] fainted!"
sleep(10)
Attacker << "You gained [round((Defender.Experience/Attacker.Level)*3.4)] experience!"
Attacker.Experience += round((Defender.Experience/Attacker.Level)*3.4)
Attacker.Update()
Attacker.loc = locate(Attacker.lastx,Attacker.lasty,Attacker.lastz)
Attacker.isfrozen = 1
Attacker.Target = null
del(Defender)


The only time i delete him is after deathcheck.
Hrm, try throwing a world<<"[P]" before the call, and a world<<"[Opponent]" within the Turn() proc.
turf
Weed
icon='Turfs.dmi'
icon_state= "Weed"
Entered(mob/Player/M)
if(M.Hit_Points <= 0)
return
if(prob(30))
var/mob/P = new /mob/Enemy/Shade
M.lastx = M.x
M.lasty = M.y
M.lastz = M.z
M.isfrozen = 0
M.loc = locate(M.x,M.y,4)
M.dir = EAST
P.loc=locate(M.x+1,M.y,M.z)
P.dir = WEST
M << "Lvl : [P.Level] [P] appeared! Get ready for battle!"
M.Target = P
P.Target = M
world<< "P is [P]"
world << "M is [M]"
Turn(M,P)

proc
Turn(mob/Player,mob/Opponent)
world << "Opponent is [Opponent]"
world << "Player is [Player]"
if((Player.Speed + Player.Speed_Mod) >= (Opponent.Speed + Opponent.Speed_Mod))
Player << "Its your turn!"
Player.Choose()

if((Player.Speed + Player.Speed_Mod) <= (Opponent.Speed + Opponent.Speed_Mod))
Player << "Its [Opponent] turn!"
Opponent.EChoose()


When I run it says ..
P is Shade
M is Julian
Opponent is Shade
Player is Julian
Is that the ONLY place you're calling Turn()? Do you call it anywhere else, without the proper arguments?
No thats the only place. Maybe it has something to with with Entered(). Cause im saving the x,y,and z coordinates and after battle I warp back to it which could cause Entered() again?? Idk just a thought.
Well I tested that theory and that's not it.
Directly setting x/y/z doesn't call Move(), so Entered() doesn't get called iirc. When do you get the error? At the start of the fight? In the middle? At the end?
At the end when i'm going back to coordinates
Once i teleport out it shows that error
Does the error occur every time? Some times? Rarely?
runtime error: Cannot read null.Speed
proc name: Turn (/proc/Turn)
source file: Datums.dm,16
usr: Julian (/mob/Player)
src: null
usr.loc: Weed (8,31,1) (/turf/Weed)
call stack:
Turn(Julian (/mob/Player), null)
Weed (8,31,1) (/turf/Weed): Entered(Julian (/mob/Player), Grass (8,32,1) (/turf/Grass))
Oh I think I see what's happening. Check what happens after the mob dies, it might be happening in the stack, which might mean Turn() gets called again despite the fight actually being over, and the mob being deleted.
Does it most times then none
Page: 1 2