The game I am making requires a function to be called every three seconds or so, making something like this ideal:
world
New()
mainfunction()
proc
mainfunction(){
/*Do some stuff*/
sleep(30)
mainfunction()
}
The problem is that the call stack becomes infinitly long, and crashes Dream Seeker. My question, then, is what is the best way to have something like this? The only way I could think of was to put the code I needed in the host-mob's Stat() proc, so that it would be called often without adding to the call stack... this, however, would cause more problems then it is worth. Is there a function which is called by the world every couple seconds, which I could redefine to meet my needs? Is there anyway around the infinite call stack problem? Anyone have any ideas?
ID:153251
Aug 23 2004, 11:19 pm
|
|
Aug 24 2004, 12:13 am
|
|
spawn() it.
|
In response to Hazman
|
|
Does Spawning clear the call stack (and prevent crashes)? If it does, it should really be put into the documentation as one of it's features.
|
In response to Elshender
|
|
I thought it was mentioned there. Maybe not.
Another option is to do: proc mainfunction() while(world) /*Do some stuff*/ sleep(30) while(world) is really equivalent to while(1), but I think it's conceptually neater. Also, brackets are unnecessary in DM. All that matters is the indention. |
In response to Elshender
|
|
spawn() creates a new thread.
|
In response to Garthor
|
|
Strictly speaking, I don't think you can say that. I don't believe BYOND is threaded. In practice, though, that's more or less what's going on.
|