It is impossible to make walking NPC's without them having freezing/crashing the game because it requires an infinite loop unless there is a way through this. I've tried several ways.
1) Global Loop (Freeze)
2) self-loop (Freeze)
3) Stat()? (would this even work well?)
Those are the only 3 main ways I can think of. I see many games like Mystic Journey with many, and I mean many walking NPCs (squirrels, enemies, and other npc's) and there server don't freeze a lot.
ID:171167
Nov 1 2004, 3:14 pm
|
|
Nov 1 2004, 3:15 pm
|
|
Use Sleep() or Spawn() to give walking/attacking a delay.
|
In response to Roara
|
|
Yes, I have this. The game usually freeze after 30 or more minutes. I hosted the game without the any infinite loops and it stayed up without crashing or freezing but with the loop on, it freezes after a while.
|
In response to VUnit321
|
|
Yeah, one thing that always helps with recursive functions in BYOND is to allow the calling process to finish out after it calls it's copy. ie:
mob This way, we don't have procs continually being pumped into memory, and never going out. When you have only a few things that do this, it may not be very noticable, but if you have a whole lot, you're in for some CPU hurt :) Hopefully this'll help you out a bit with your game. |
In response to Igmolicious
|
|
..() is not the calling process, rather it is the parent type's version of the same function in which it is called. So if you do this:
mob/NPC/proc/walkAround() That is calling mob/walkAround. If there is no mob/walkAround then the ..() would be meaningless as it has nothing to call. The programmers of Byond are actually planning to put in a warning at compile-time when that is used without any parent function to have it call. |
There are two ways to avoid the infinite recursion setback. Either use spawn (as Roara mentioned) or set it up so that the function loops within itself instead of continually calling itself. The sleep function will not work for this.
mob/npc/proc/recursive_version() spawn allows the current function to continue before executing its code block (that being calling recursive_version in this example), which allows that function to return assuming it doesn't hang up before the end. The looping version should be self-explanitory. It just loops until its src is deleted or the world is shut down. |
In response to Loduwijk
|
|
I stand corrected.
|
In response to Loduwijk
|
|
Loduwijk wrote:
There are two ways to avoid the infinite recursion setback. Either use spawn (as Roara mentioned) or set it up so that the function loops within itself instead of continually calling itself. The sleep function will not work for this. This is my current game ticker which does all the events. I have the GameTicker. What you have in your looping version is similar to mines. var/GameTicker/GameTicker |