ID:262492
 

cavey1
name = "Beholder"
icon = 'NPC.dmi'
icon_state = "beholder"
Health = 100
Mhealth = 100
exp = 200
player = 0
var/mob/P
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
if(P in oview(5)) //if a Player comes in 5 steps of him
step_towards(src,P) //Chase him!
for(P in oview(1))
Fight(P)
break //if you want your NPC to shoot make it so
for(P in oview(2))
Fight(P) //these are saying if the Player is within 1,2,3,4 blocks do nothing
break
for(P in oview(3))
Fight(P)
break
for(P in oview(4))
break
else
step_rand(src) //if no NPC is 5 blocks or less away walk around
sleep(10) //stop for 1 second
for(P in oview(5))
break
sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(M.player == 1)
Fight(M)
else
return

proc/Fight(mob/M)
if(usr.wait == 0)
var/damage = rand(1,15)
M.Health -= damage
M << "[src] shoots a magical beam at you for [damage] damage!"
src<<"You attack [M] for [damage] damage!"
Dcheck(M)
usr.wait = 1
spawn(10)
usr.wait = 0


I get 1 runtime error, many times, it seems like I get 1 runtime error for every time one of thse moves on the map. I get the error:

runtime error: Cannot read null.Mhealth
proc name: Dcheck (/mob/proc/Dcheck)
usr: Vampire Bat (/mob/HIM/cavey2)
src: Vampire Bat (/mob/HIM/cavey2)
call stack:
Beholder (/mob/HIM/cavey1): Dcheck(null)
Beholder (/mob/HIM/cavey1): Fight(null)
Beholder (/mob/HIM/cavey1): Wander()
Beholder (/mob/HIM/cavey1): New(the cave (835,146,1) (/turf/cave))
with the coordinates and name of critter changed slightly or not at all in each error. They come, like, 5 per second...


What on earth does it mean?


--Vito
Try changing the variable to var/mob/HIM/P
In response to Sinoflife
Yea, do what Sin said. That code looks oddly familiar, but what the heck. Almost all real-time combat codes look the same.
In response to Sinoflife
Then the dumb things chase each other!

--Vito
In response to Killerdragon
I have tried it, but I'll do again... That's it... I'm building this code from the bottom up again...

EDIT: ummm, now, after building, the game freezes Dream Seeker after like 2 seconds of runtime. Why would this be?

--Vito
Read the usr lecture, Lummox's usr friendly, and we need to see your dcheck.
cavey1
name = "Beholder"
icon = 'NPC.dmi'
icon_state = "beholder"
Health = 100
Mhealth = 100
exp = 200
player = 0
New()
. = ..()
spawn()
Wander()
proc/Wander()
var/mob/P
while(src)
if(P in oview(5)) //if a Player comes in 5 steps of him
step_towards(src,P) //Chase him!
for(P in oview(1))
Fight(P)
break //if you want your NPC to shoot make it so
for(P in oview(2))
Fight(P) //these are saying if the Player is within 1,2,3,4 blocks do nothing
break
for(P in oview(3))
Fight(P)
break
for(P in oview(4))
break
else
step_rand(src) //if no NPC is 5 blocks or less away walk around
sleep(10) //stop for 1 second
for(P in oview(5))
break
sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(M.player == 1)
Fight(M)
else
return

proc/Fight(mob/M)
if(M.wait == 0)
var/damage = rand(1,15)
M.Health -= damage
M << "[src] shoots a magical beam at you for [damage] damage!"
src<<"You attack [M] for [damage] damage!"
Dcheck(M)
M.wait = 1 // Either M or src, don't use usr. Also, you should remove the src message, since the message is going to the monster.
spawn(10)
M.wait = 0
In response to Vito Stolidus
Probably an infinite loop.
In response to Jp
How would it be an infinite loop? Undefined type is an undefined type. Nothing to do with an infinite loop.
In response to Sinoflife
You may want to click on Parent ID, I think he was refering to:
ummm, now, after building, the game freezes Dream Seeker after like 2 seconds of runtime. Why would this be?
In response to Ol' Yeller
Hmmm... I have the monsters set to theoretically work, however, I can't test it because I can't find and kill a monster in 2 seconds. I am pretty sure it has little to do with the monsters though, so you can name all the possible ways I could freeze Dream Seeker so I can check them. That would help

--Vito
Vito Stolidus wrote:
I get 1 runtime error, many times, it seems like I get 1 runtime error for every time one of thse moves on the map. I get the error:
What on earth does it mean?

Welcome to Runtime Error Reading 101!

<font color=red>runtime error: Cannot read null.Mhealth</font>
<font color=blue>proc name: Dcheck (/mob/proc/Dcheck)</font>
<font color=red> usr: Vampire Bat (/mob/HIM/cavey2)
src: Vampire Bat (/mob/HIM/cavey2)</font>
<font color=blue> call stack:
Beholder (/mob/HIM/cavey1): Dcheck(null)
Beholder (/mob/HIM/cavey1): Fight(null)
Beholder (/mob/HIM/cavey1): Wander()
Beholder (/mob/HIM/cavey1): New(the cave (835,146,1) (/turf/cave))</font>

Ok, Lets start with the first red line:
Cannot read null.Mhealth! That means, you're trying to look at the Mhealth variable for something that doesn't exist. An easy fix to that would be: if(! [atom refference] ){return}

First blue line: proc name: Dcheck (/mob/proc/Dcheck)
Ok, this error occured in the Dcheck proc, the proc's path is /mob/proc/Dcheck.

Next Red Line: The user of the proc was Vampire Bat (it's type was /mob/HIM/cavey2. The source of the proc was also Vampire Bat (type was /mob/HIM/cavey2)

Next Blue Line: The call stack! This is a list of events leading up to this, in order of most recent, to earliest.
Beholder (/mob/HIM/cavey1): New(the cave (835,146,1)
That called: Beholder (/mob/HIM/cavey1): Wander()
Which called: Beholder (/mob/HIM/cavey1): Fight(null)
Which finally called Beholder (/mob/HIM/cavey1): Dcheck(null)

Alright! So now that you understand the error, and what things are, now it's time to understand that lag problem you had.

        proc/Wander()
while(src)
if(P in oview(5))
step_towards(src,P)
for(P in oview(1))
Fight(P)
break
for(P in oview(2))
Fight(P)
break
for(P in oview(3))
Fight(P)
break
for(P in oview(4))
break
else
step_rand(src)
sleep(10)
for(P in oview(5))
break

Ok, it's lagging, because there is infact an infinite loop.
It never leaves that while() statement until the source of this procedure is deleted! Which means you need to add a break to leave the while, or find a more efficient way to do this. (Right now, it's pretty ugly and approximately every second it does that stuff twice!)

As simple thing to fix the null problem here, is for your 'fighting mobs in view 1, 2, and 3'
                    for(var/n=1 to 3)
for(var/mob/Mob in oview(n))
if(!Mob){continue}
Fight(Mob)
break

Though even in that, there's a situation, what if there were a mob in view 1, a mob in view 2, and a mob in view 3? Then it would fight all 3 at once. I'll let you find the solution.
~Jack
In response to JackGuy
I have fixed 'em all. Have had em fixed for days. Help me with my other problem(see below)

EDIT: Strike One for JackGuy

--Vito
In response to Vito Stolidus
Post 'Deleted' due to misunderstanding of previous post.
In response to JackGuy
No No No!!!!!!!!!!!!!! I don't want monsters frozen. If you didn't bother to read the thread, my WHOLE GAME freezes a few seconds after login! That's the problem.

Strike Two for JackGuy...


--Vito
In response to Vito Stolidus
If you read my first post, I showed you that there was an infinite loop caused by monsters' Wander proc. Infinite loops cause extreme lag. I told you a fix for that. Re-read it, if you even did in the first place.
~Jack
In response to JackGuy
Nope, still freezes after I log in, even after fixing that. Any other ideas?

Foul! (almost another strike)

--Vito
In response to Vito Stolidus
He's just trying to help, stop freeking out.

"If you didn't bother to read the thread"

If you didn't bother to read the countless people posting, don't use usr in the proc, or not to do if(var==1) then maybe you shouldn't be programming until you learn the basics.
In response to Vito Stolidus
If you're going to bite the hand of the people that help you, then you're in trouble down the road.
Remember... none of us are obligated to help you, we're helping you out of our own free will.

I told you, your current Wander procedure was ugly, and that there are situations with how some things were done. Did you even fix the wander infinite loop?
If so, increase the time it waits to do another wander proc. Give it maybe a second or two. Make a variable for a mob it's attacking, and have a check so if it already has a target- not to search for another.
There's tons of things you can do, but I'm not going to serve you code on a silver platter, you have to learn yourself.
[EDIT]
The easiest solution is to eliminate the wander proc itself.
Comment it out, and see if there's still lag. If so, that's not the thing.
Think of a way to have things move only when a player is near.
Having it not call the proc so much, and only when necessary is how you should have it.
[/EDIT]

I bet you didn't even read that... but now you're going back up to read it...
In response to JackGuy
...Actually, no I read your whole post. I read all posts that interest me fully, unless there are like 200 posts (see subject "London Terror" in Community) I'll comment it out, but lag isn't the problem: MY PROGRAM FREEZES THE DREAM SEEKER. It goes "Not Responding" and dies.

Who's biting off the hand? I have habits, like the
 if(var == 1)
// instead of
if(var)

habit because I started programming in C++. If you've used it, you will know. You can't use if(var) in C++, but you can use if(var == 1), and since it works here... And I'm not snapping at you, its just I don't want this thread to go off topic too badly. I've had many a good thread ruined that way.


EDIT: Commenting out the wander proc fixes the freeze. Thank you! [It's a Hit! That error's going... going... Gone! JackGuy has hit a home run!]

--Vito
Page: 1 2