ID:851677
 
(See the best response by Albro1.)
Code:
mob/monster
var/horny
var/hunger
Slurry_Goggler
icon = 'monsters.dmi'
icon_state = "testmonster"
New()
spawn()
Hunt()
proc/Hunt(var/mob/M)
while(src)
if(M in oview(3))
if(M.client)
if(src.hunger <= 5)
step_towards(src,M)
sleep(5)
step_towards(src,M)
sleep(5)
step_towards(src,M)
else
return
else if(istype(M,/mob/monster/Slurry_Goggler))
if(src.horny<= 5)
step_towards(src,M)
sleep(5)
step_towards(src,M)
sleep(5)
step_towards(src,M)
else
return


Problem description:
I coded a monster AI doesn't work and lags the game up. It take approximately 20 seconds longer to load with the code.

Dear god, what kind of game are you making?

You've got something infinite loop there. Try setting hunt to background proc.
Best response
Give Hunt() a delay. Add a sleep(1) at the end. This will give other procedures that are waiting to activate a chance to do so.
In response to Lugia319
Lugia319 wrote:
Dear god, what kind of game are you making?
If you're asking about the horny var, I just use that for the animals to reproduce, since I find it unrealistic for them to just respawn. Hell, you could even wipe out the entire population of rabbits if you were really determined.

You've got something infinite loop there. Try setting hunt to background proc.

Umm... how do I do that xD
In response to Albro1
Albro1 wrote:
Give Hunt() a delay. Add a sleep(1) at the end. This will give other procedures that are waiting to activate a chance to do so.

I tried that, it made the game load in an instant, but it freezes.
Does it tell you that you have an infinite loop?
Oh boy... you would get better results from studying the many AI libraries. They provide good basic AI with a lot of commentary. You seem capable of modifying what you need from those.

http://www.byond.com/developer/?text=AI&sort=pop

In response to Albro1
Albro1 wrote:
Does it tell you that you have an infinite loop?

No, when I tried your method, it loaded fine, but the login screen would freeze.
Trying Lugia's Method, everything worked fine, but the framerate was still very slow
Put this in your code:
#define DEBUG
Still no errors or debug reports. It's all just lag and an unresponsive monster.
And Jittai,
I hate using other people's code since it takes away the pride of independence.(Or at least your work)
Using other people's code to figure out how to do something is not something to be ashamed of. We all have to learn from somewhere. Once you figure it out, you can remake it to your liking. What's important now is that you use what resources you have wisely and learn.
^. They made the library for a reason. There's no need to break your neck figuring out something someone else already has done.