ID:176435
 
for any of you who had read my last thread knows of my npc problem. I've stumbbled upon a bug and i need some help on it, anyone willing to help, post your aim sn and/or your email, the files are small but to big to put on the forum so if you could spare a few minutes of your lives to help an eager to learn newbie i would be very appreciative!


mob/Move()
if(movable == 1)
..()
else
return

proc/Move_mobs()
for(var/mob/M in world)
if(!M.client)
if(M.old == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(50,60))

Move_mobs()


if(M.young == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(5,15))

Move_mobs()

if(M.adult == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(30,40))

Move_mobs()

if(M.still == 1)
return 0

world/New()
..()
Move_mobs()

ok this is where i think the problem is, when i had a npc with adult = 1 another with old = 1 and another with young = 1, after a few seconds the npcs move REAL fast
In response to Erdrickthegreat2
That's because you're moving every mob in the world every few seconds for every mob in the world.
In response to Garthor
well what should i do to fix that? Nadrew said call the Move_mobs() proc on the NPC's New() proc, and get rid of the for loop. Think that would work? [EDIT]
ok this is what i got so far...

mob

New()
..()
if(!src.client)
src.Move_mobs()
else
return 0


mob/proc/Move_mobs()
var/mob/M
if(!M.client)
if(M.old == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(50,60))
Move_mobs()


if(M.young == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(5,15))
Move_mobs()

if(M.adult == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(30,40))
Move_mobs()

if(M.still == 1)
return 0
mob
var
young = 0
old = 0
adult = 0
still = 0

when i run this i get this error..
runtime error: Cannot read null.client
proc name: New (/mob/New)
usr: Townsman (/mob/Townsman)
src: Townsman (/mob/Townsman)
call stack:
Townsman (/mob/Townsman): New(the grass (4,2,1) (/turf/grass))
runtime error: Cannot read null.client
proc name: New (/mob/New)
usr: Oldman (/mob/Oldman)
src: Oldman (/mob/Oldman)
call stack:
Oldman (/mob/Oldman): New(the grass (7,6,1) (/turf/grass))
runtime error: Cannot read null.client
proc name: New (/mob/New)
usr: Child (/mob/Child)
src: Child (/mob/Child)
call stack:
Child (/mob/Child): New(the grass (3,9,1) (/turf/grass))
runtime error: Cannot read null.client
proc name: Move mobs (/proc/Move_mobs)
usr: null
src: null
call stack:
Move mobs()
: New()
runtime error: Cannot read null.client
proc name: New (/mob/New)
usr: the mob (/mob)
src: the mob (/mob)
call stack:
the mob (/mob): New()

what am i doing wrong?
In response to Erdrickthegreat2
I personally don't like !Variable. It just confuses me. :D I just use a if(var == 0) (Same thing, look up "!" in the refrence.) I think the problem is that client is null, and it can't see if it is zero. (!A returns 1 if A == 0, 0 otherwise) So, instead use if(src.client == null)

Hope I'm right, just try it.

-<font color="#ffff00">Nova</font>
In response to Nova2000
Nova, this has been said to you before, but it looks like I have to repeat it: Please don't try to help people when you don't know what you're talking about.

This is how ! really works:

<code>if (!A) src << "A is null, 0, or an empty text string" else src << "A is not any of the following: null, 0, empty text string"</code>
In response to Crispy
Crispy wrote:
Nova, this has been said to you before, but it looks like I have to repeat it: Please don't try to help people when you don't know what you're talking about.

This is how ! really works:

<code>if (!A) > src << "A is null, 0, or an empty text string" > else > src << "A is not any of the following: null, 0, empty text string"</code>

Does that make my method of checking for null by if(var == null) wrong? As I stated in my post, I didn't prefer !. Trying to offer some help, I did look it up in the refrence:
"1 if A is zero; 0 otherwise."

-<font color="#ff0000">Nova</font>
P.S. Should I tack this piece of pointlessness on?
Crispy, this has been said to you before, but it looks like I have to repeat it: Users of this forum should use the <DM> tag to highlight code, not a <CODE>
In response to Nova2000
your just argueing, this still doesn't help my problem
In response to Nova2000
Your method is perfectly valid. The only reason I corrected you was to avoid confusing Erdrick.

The reason I don't use the <DM> tag is the same reason you don't use ! - I don't like it. It tends to put in extra whitespace, which I hate having to deal with. Therefore, I use <code>. <code> also has another advantage - it allows the lines to wrap, so people don't have to scroll sideways to view all of the code if there's a long line.

The only reason I would ever use <DM> is if there were HTML tags within the code that I wanted to prevent affecting the style of the output (e.g. making all the text from that point onwards red). If there are no HTML tags, or I don't want to stop the tags affecting the style of the output, then I use <code>.
In response to Erdrickthegreat2
In mob/New(), change the line:

<code>if(!src.client)</code>

To:

<code>if(src && !src.client)</code>
In response to Crispy
it didnt do anything, i get the same error, this is the whole code..

mob/Move()
if(movable == 1)
..()
else
return
mob

New()
..()
if(src && !src.client)
src.Move_mobs()
else
return 0


mob/proc/Move_mobs()
var/mob/M
if(!M.client)
if(M.old == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(50,60))
Move_mobs()


if(M.young == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(5,15))
Move_mobs()

if(M.adult == 1)
step(M, pick(NORTH, EAST, SOUTH, WEST))
spawn(rand(30,40))
Move_mobs()

if(M.still == 1)
return 0
mob
var
can = TRUE
movable = 1
txt
open = 1
young = 0
old = 0
adult = 0
still = 0


client

Center()
if(mob.can)
mob.can = 0
for(var/mob/M in oview())
if(!get_dir(mob,M))
else if(!M.client)

M.Talk(mob)
sleep(1)
mob.can = 1
Northwest()
if(usr.can)
usr.can = 0
usr.close_menu()
usr.movable=1
usr.can = 1
usr.open = 1

mob

Townsman
icon = 'dw4townsman.dmi'
txt="Give me a freaken sammich!"
adult = 1
Oldman
icon = 'dw4wiseman.dmi'
txt="I'm way too old."
old = 1
Child
icon = 'dw4child.dmi'
txt = "I can run fast!"
young = 1

proc/Talk(mob/user)

set src in world
if(usr.open == 0)

else if(usr.open == 1)
if(get_dir(usr,src) != usr.dir)
usr.movable=0
usr<<sound('beep.wav')
user.textonscreenbackground(1,1,13,5)
usr<<sound('txt.wav',1)
user.textonscreenTEXT(1.5,12.5,4.5,1.5,"~There is no one there!'")
usr.open = 0
sleep(1)
usr<<sound()
return
else if(src in oview(1))
src.dir = get_dir(src,user)
usr.movable=0
src.movable=0
usr<<sound('beep.wav')
user.textonscreenbackground(1,1,13,5)
usr<<sound('txt.wav',1)
user.textonscreenTEXT(1.5,12.5,4.5,1.5,"~[src.txt]'")
usr.open = 0
sleep(1)
usr<<sound()
src.movable=1
else
usr.movable=0
usr<<sound('beep.wav')
user.textonscreenbackground(1,1,13,5)
usr<<sound('txt.wav',1)
user.textonscreenTEXT(1.5,12.5,4.5,1.5,"~There is no one there!'")
usr.open = 0
sleep(1)
usr<<sound()
return
mob/proc
close_menu(){for(var/obj/text/O in client.screen)del O;for(var/obj/back/O in client.screen)del O}
TOSP(var/textonscreen){text1=list();for(var/ a=1,a<=length(textonscreen),a++){text1+=copytext(textonsc reen,a,a+1)}}
textonscreenbackground(var/XC1,YC1,XC2,YC2)
for(var/XC=XC1,XC<=XC2,XC++)
for(var/YC=YC1,YC<=YC2,YC++){var/obj/back/b=new(client);
if(XC==XC1)b.icon_state="l";if(XC==XC2)b.icon_state="r";if(Y C==YC1)b.icon_state="b";
if(YC==YC2)b.icon_state="t";if(XC==XC1&&YC==YC1)b.icon_state ="ll";
if(XC==XC2&&YC==YC2)b.icon_state="ur";if(XC==XC1&&YC==YC2)b. icon_state="ul";
if(XC==XC2&&YC==YC1)b.icon_state="lr";b.screen_loc="[XC],[YC]"}
textonscreenTEXT(var/XC1,XC2,YC1,YC2,T)
var{XC=XC1;YC=YC1}TOSP(T)
for(var/Y in text1){var/obj/text/C=new(client);
if(XC==round(XC)&&YC==round(YC)) C.screen_loc="[XC],[YC]";else if(XC!=round(XC)&&YC==round(YC))C.screen_loc="[XC-0.5]:16,[Y C]";else if(XC==round(XC)&&YC!=round(YC))C.screen_loc="[XC],[YC-0.5]: +16";
else if(XC!=round(XC)&&YC!=round(YC))C.screen_loc="[XC-0.5]:16,[Y C-0.5]:+16";C.icon_state="[Y]";
sleep(0.5)
XC+=0.5
if(XC==XC2)
XC=XC1;YC-=0.5
if(YC==YC2-0.5)break}
mob/var/text1
obj
back
icon='back.dmi'
layer=MOB_LAYER+4
New(client/C)C.screen+=src
text
icon='text.dmi'
layer=MOB_LAYER+5
New(client/C)C.screen+=src
I used raekwons demo..

In response to Erdrickthegreat2
Oh, wait... DOH! :-)

It's parsing the !src bit before the src.client bit, so it's basically the same as saying null.client - which is of course why you get the error.

So simple, so obvious, yet so... unneccessary. Dantom, I think this is something to change... o_0

Change that line I mentioned before to:

<code>if(!client)</code>