ID:171841
 
runtime error: Cannot read null.Exp
proc name: ExpBar (/mob/proc/ExpBar)
usr: XzDoG (/mob/Choose)
src: Player (/mob/Player)
call stack:
Player (/mob/Player): ExpBar(null)
XzDoG (/mob/Choose): NewGame()
XzDoG (/mob/Choose): Login()

mob/proc/NewGame()
New.ExpBar()
new/obj/MeterEnd/Left(src.client)
new/obj/MeterEnd/Right(src.client)
new/obj/Meter/Experience1(src.client)
new/obj/Meter/Experience2(src.client)
new/obj/Meter/Experience3(src.client)
del(src)
..()


mob/proc/ExpBar(mob/Player/M)
var/Meter_Width = 17
var/Percent = round(M.Exp/M.MaxExp * Meter_Width * 3)
for(var/obj/Meter/Experience1/H in M.client.screen)H.icon_state = "[(Percent>Meter_Width)?(Meter_Width-1):Percent]"
for(var/obj/Meter/Experience2/H in M.client.screen)H.icon_state = "[(Percent>(Meter_Width*2))?(Meter_Width-1):Percent-Meter_Width]"
for(var/obj/Meter/Experience3/H in M.client.screen)H.icon_state = "[Percent-(Meter_Width*2)]"
if(M.Exp==M.MaxExp)for(var/obj/Meter/H in M.client.screen)H.icon_state="18"


Help me fix this runtime please?
It helps when you read the runtime errors. If it told you the problem was null.Exp and it told you which proc (and if you turn on debugging info in the menu via Build | Preferences, you get a line number too), then you can see easily what the problem is.

The only something.Exp there is M.Exp. Hence, M is the null in the null.Exp error.

A quick glance at where you called the proc makes it obvious that you never sent an argument to ExpBar(). Since there's no argument to fill in for M, M is null. Solution: Call your proc correctly.

Lummox JR
In response to Lummox JR
Well lummox thats why im a newbie :p
after reading what you said i went back and realised once again i didnt call the proc correctly.
:EDIT:
Now i have a new runtime

runtime error: Cannot read null.screen
proc name: ExpBar (/mob/proc/ExpBar)
source file: Meter.dm,81
usr: XXXXXXX (/mob/Player)
src: Spirit (/mob/Monster/DoomedSpirit)
call stack:
Spirit (/mob/Monster/DoomedSpirit): ExpBar(Spirit (/mob/Monster/DoomedSpirit))
Spirit (/mob/Monster/DoomedSpirit): DeathCheck(XXXXXXX (/mob/Player))
XXXXXXX (/mob/Player): Attack(Spirit (/mob/Monster/DoomedSpirit))
Spirit (/mob/Monster/DoomedSpirit): MonsterAttack(XXXXXXX (/mob/Player))
XXXXXXX (/mob/Player): StartBattle(Spirit (/mob/Monster/DoomedSpirit))
Spirit (/mob/Monster/DoomedSpirit): Bumped(XXXXXXX (/mob/Player))
XXXXXXX (/mob/Player): Bump(Spirit (/mob/Monster/DoomedSpirit))

    for(var/obj/Meter/Experience1/H in M.client.screen)H.icon_state = "[(Percent>Meter_Width)?(Meter_Width-1):Percent]"//Line 81
Once again am i calling the proc wrong where its being called(Its not in the login if you need the snippet tell me).
In response to XzDoG

mob/proc/ExpBar(mob/Player/M)
var/Meter_Width = 17
var/Percent = round(M.Exp/M.MaxExp * Meter_Width * 3)
for(var/obj/Meter/Experience1/H in M.client.screen)H.icon_state = "[(Percent>Meter_Width)?(Meter_Width-1):Percent]"
for(var/obj/Meter/Experience2/H in M.client.screen)H.icon_state = "[(Percent>(Meter_Width*2))?(Meter_Width-1):Percent-Meter_Width]"
for(var/obj/Meter/Experience3/H in M.client.screen)H.icon_state = "[Percent-(Meter_Width*2)]"
if(M.Exp==M.MaxExp)for(var/obj/Meter/H in M.client.screen)H.icon_state="18"


Although i am not posative the debug mode says its in the Expbar coding but where its called in the deathcheck is where i get the runtimes.
:edit: ive shown the line with the error above in the last post.
In response to XzDoG
You're going to want to make sure M even HAS a client before trying to access M.client.
In response to Garthor
Well Xooxer helped me in chatters so i dont need help with the above anymore however i do need help with this.
mob
login()
new/obj/MeterEnd/Left(src.client)
new/obj/MeterEnd/Right(src.client)
new/obj/Meter/Experience1(src.client)
new/obj/Meter/Experience2(src.client)
new/obj/Meter/Experience3(src.client)
src.ExpBar()

//Exp Proc
mob/proc/ExpBar()
if(!src.client)return
var/Meter_Width = 17
var/Percent = round(src.Exp/src.MaxExp * Meter_Width * 3)
if(src.Exp==src.MaxExp)
for(var/obj/Meter/H in src.client.screen)
H.icon_state="18"
return
for(var/obj/Meter/Experience1/H in src.client.screen)
H.icon_state = "[(Percent>Meter_Width)?(Meter_Width-1):Percent]"
for(var/obj/Meter/Experience2/H in src.client.screen)
H.icon_state = "[(Percent>(Meter_Width*2))?(Meter_Width-1):Percent-Meter_Width]"
for(var/obj/Meter/Experience3/H in src.client.screen)
H.icon_state = "[Percent-(Meter_Width*2)]"

Thats how im calling my update for ExpBar however it only works in login(which is the example) and not in the actual game which its called the same way how would i go about making itself update in the game and not just by logging in and out?
In response to XzDoG
well i was able to fix the exp bar however i have a new problem with meters everytime i login it seems to add another full hp meter on and making players look like they have alot of hp and the bar doesnt update but the bar is updating please take a look at this:
mob/Player/Login()
..()
src.Bars()

mob/var/HealthOverlay
mob/var/MagicOverlay

mob/proc/Bars()
src.overlays -= src.HealthOverlay
var/obj/HealthBar/O = new/obj/HealthBar
var/Length = 30
var/Percent = round((src.Health/src.MaxHealth) * Length)
O.icon_state = "[(Percent>Length)?(Length-1):Percent]"
if(Percent==30)
O.icon_state = "30"
src.HealthOverlay = O
src.overlays += src.HealthOverlay
src.overlays -= src.MagicOverlay
var/obj/MagicBar/A = new/obj/MagicBar
var/Length1 = 30
var/Percent1 = round((src.Mana/src.MaxMana) * Length1)
A.icon_state = "[(Percent1>Length1)?(Length1-1):Percent1]"
if(Percent1==30)
A.icon_state = "30"
src.MagicOverlay = A
src.overlays += src.MagicOverlay


obj/HealthBar
icon='meter.dmi'
icon_state="29"
pixel_y=-32
layer=-4

obj/MagicBar
icon='Manameter.dmi'
icon_state="29"
pixel_y=-40
layer=4
In response to XzDoG
It doesn't make sense that you're trying to use overlays with screen objects here. I've used both before but only in cases where a screen object wasn't big enough and I wanted to use pixel offsets to cover more tiles. That's not what you're doing here.

I think you have the wrong idea on when to use overlays and what they can be used for.

Lummox JR
In response to Lummox JR

I think you have the wrong idea on when to use overlays and what they can be used for.

Well my interpretation of it was that i could apply overlays to anything if i needed an image ontop of something but if i shouldnt be doing this with screen objs(I.E My HP bar system) then how can i do it?
In response to XzDoG
XzDoG wrote:
Well my interpretation of it was that i could apply overlays to anything if i needed an image ontop of something but if i shouldnt be doing this with screen objs(I.E My HP bar system) then how can i do it?

It's starting to look to me like you actually changed over partially from the screen object approach and are now just using overlays period.

But really the key question is: Where do you want the HP bar to appear?

Lummox JR
In response to Lummox JR
But really the key question is: Where do you want the HP bar to appear?

Lummox JR

Well under the player hence(spelling?) pixel_y=-32 i did overlays so everyone could see each players health and mana bars. You see Lummox it works fine until the player logs out then in again it resets the HP/Mana bar (Either re-adds the overlay or sets the icon back to default) and im not sure how to fix that.
In response to XzDoG
The Proc:
mob/proc/Bars()
src.overlays-=src.HealthOverlay
var/obj/HealthBar/O=new/obj/HealthBar
var/Length=30
var/Percent=round(src.Health/src.MaxHealth*Length)
O.icon_state = "[(Percent>Length)?(Length-1):Percent]"
if(Percent<=0)O.icon_state = "0"
if(Percent==30)O.icon_state = "30"
src.HealthOverlay=O
src.overlays+=src.HealthOverlay
src.overlays-=src.MagicOverlay
var/obj/MagicBar/B=new/obj/MagicBar
var/Length2=30
var/Percent2=round(src.Mana/src.MaxMana*Length)
B.icon_state = "[(Percent2>Length2)?(Length2-1):Percent2]"
if(Percent2<=0)B.icon_state = "0"
src.MagicOverlay=B
src.overlays+=src.MagicOverlay


Its called this way:
[EDIT] and removed because it was pure crap.
[/Edit]
I Revised it alittle and it works for monsters but not the players, whats up?
In response to XzDoG
The entire if() structure in New() is not only redundant, it's preventing it from working. You're just calling src.Bars() either way, and in mob/New(), client isn't even assigned.
In response to Garthor
//For Players
mob/Player/Stat()
if(src.islocked == 0)
statpanel("Stats")
//the rest
if(istype(src,/mob/Player))
src.Bars()
//For Monsters
mob/New()
if(!src.client)
if(istype(src,/mob/Monster))
src.Bars()


Better? Also im still having the same problem. It works fine when you create a character but once you logout then in again it starts messing up as i explained a few posts ago.
In response to XzDoG
Oh, you shouldn't be using usr in procs.
In response to Garthor
Garthor wrote:
Oh, you shouldn't be using usr in procs.

Since when is Stat() a proc?
In response to XzDoG
since it had () at the end. -_-'
In response to Airjoe
Airjoe wrote:
since it had () at the end. -_-'

Ah, see i never knew that so thanks for pointing that out i got rid of the usr now.
In response to XzDoG
Ok i fixed it and heres how incase anyone has any problems like this in the future..
        if(istype(src,/mob/Player))
Start
src.overlays-=src.HealthOverlay
src.overlays-=src.MagicOverlay
src.Bars()
src.ExpBar()
goto Start


I Figured out eventually it would add so many overlays it couldnt remove all of them so i had it loop so it removes them all.

:EDIT:

This way is waaaaaaaaayyyyyy to processor intensive can i do it any other way?
In response to XzDoG
Delay it, and don't use goto! While() is better for that.

if(istype(src,/mob/Player/))
while(src)
sleep(8)
src.overlays-=src.HealthOverlay
src.overlays-=src.MagicOverlay
src.Bars()
src.ExpBar()
Page: 1 2