ID:261426
 
Im having trouble with a proc that gives the usr the amount of exp that is assigned to the NPC in a var. Im getting a runtime error. yuck :(

//////////////////////CODE\\\\\\\\\\\\\\\\\\\\\\\
Win(mob/NPC/Monster/Rat/M)
usr.Experience += M.exp
alert("Congratulations: You gain [usr.Experience] Experience and 5 Silver Coins!"

///////////////////RUNTIME ERROR\\\\\\\\\\\\\\\\\
runtime error: Cannot read null.exp
proc name: Win (/turf/Battleverbs/Attack/proc/Win)
source file: Attack.dm,57
usr: GM Little Sally (/mob/PC)
src: Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack)
call stack:
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Win(null)
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): PCAttack()
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Click(Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack))



If you need anymore code please let me know :)

Thanks,
Little Sally
you need to look for M by doing in oview() something or other I think... try it.
That means the /mob/NPC/rat's exp var is null or it has no exp var.
In response to Nadrew
But it does



Code
Monster
var
monster= 1
Rat
icon ='Rat.dmi'
name ="Rat"
var
HPnpc = 6
Strengthnpc = 1
Defencenpc = 0
exp = 5
In response to Nadrew
Hmm... I have messed with it for awhile and can't get it to work. Is there another wat to do this?
Little Sally wrote:
Im having trouble with a proc that gives the usr the amount of exp that is assigned to the NPC in a var. Im getting a runtime error. yuck :(

//////////////////////CODE\\\\\\\\\\\\\\\\\\\\\\\
<font color="blue">
> Win(mob/NPC/Monster/Rat/M)
> usr.Experience += M.exp
> alert("Congratulations: You gain [usr.Experience] Experience and 5 Silver Coins!"
>
</font>
///////////////////RUNTIME ERROR\\\\\\\\\\\\\\\\\
<font color="Red">runtime error: Cannot read null.exp
proc name: Win (/turf/Battleverbs/Attack/proc/Win)
source file: Attack.dm,57
usr: GM Little Sally (/mob/PC)
src: Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack)
call stack:
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Win(null)
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): PCAttack()
Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack): Click(Click To Attack Monster (16,146,1) (/turf/Battleverbs/Attack))
</font>


If you need anymore code please let me know :)

Thanks,
Little Sally

alright try this...
Win(mob/M)
if(istype(M,/mob/NPC/Monster/Rat))
usr.exp += M.exp

I dont know if it will work but it looks to me that the game cant find a Rat to get the exp from so it needs the For() to find it... I think. Try it and see for yourself.
In response to Canar
Ok here is more code.


proc
PCAttack()
sleep(1)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(7,145,1)
sleep(8)
usr.loc = locate(8,145,1)
sleep(1)
usr.loc = locate(9,145,1)
for(var/mob/NPC/Monster/Rat/M in locate(5,145,1))
M.HPnpc -= rand(1,3)
usr <<"You attacked!"
if(M.HPnpc <= 0)
Win()

del M


NPCAttack()

Win(mob/NPC/Monster/Rat/M)
For(var/mob/NPC/Monster/Rat/M in world)
usr.Experience += M:EXP
alert("Congratulations: You gain [usr.Experience] Exp 5 Silver!")


In response to Little Sally
for(var/mob/NPC/Monster/Rat/M in locate(5,145,1))
M.HPnpc -= rand(1,3)
usr <<"You attacked!"
if(M.HPnpc <= 0)
Win(M) //Pass M into the proc
del M


Make sure you send the monster mob to your Win proc. One of the parameters it was expecting was a mob, but since one wasn't given null was passed in and was causing the error.
In response to tenkuu
It worked! Thank you so much. And everyone else for trying ;P Thanks everyone ;P


Thanks,
Little Sally