ID:146637
 
How would I make it where a loop will go on on the user login witout causing a chanced timed error on logout

example
mob/Login()
Timecall()
mob/Logout()
del(src)

proc/Timecall()
time:
sleep(2)
src<<"Test Test"
goto time:


Problem description: See I use something like this and when i logout, if the proc is still being called because of a sleep var causes
an error to show up at a chance when someone logs out of the game.
ElderKain wrote:
How would I make it where a loop will go on on the user login witout causing a chanced timed error on logout

example
> mob/Login()
> Timecall()
> mob/Logout()
> del(src)
>
> proc/Timecall()
> time:
> sleep(2)
> src<<"Test Test"
> goto time:
>

Problem description: See I use something like this and when i logout, if the proc is still being called because of a sleep var causes
an error to show up at a chance when someone logs out of the game.
if(src) src << "Test Test"
Don't use goto for looping.

use a while loop.

mob/Login()
src.Timecall()
mob/Logout()
del(src)

mob/proc/Timecall()
while(src)
sleep(2)
src<<"Test Test"


Thats going to really lag, though, especially wiht lots of players.
In response to Airjoe
Airjoe wrote:
Thats going to really lag, though, especially wiht lots of players.

When you're forced to have objects going on a loop, it's best to stagger the delay so that they aren't doing it all at once:

mob/proc/Timecall()
while(src)
src << "Test"
sleep(rand(1,5))


Of course, it's always better to, if possible, have a global loop handle it in one shot:

proc/Timecall()
while(1)
world << "Test"
sleep(2)
In response to Wizkidd0123
I think that was just an example guys =P
In response to Airjoe
Airjoe wrote:
Thats going to really lag, though, especially wiht lots of players.

That's nonsense. Using a loop here & there doesn't create lag. Especially something THAT small in processing power. The only time I've seen loops cause great lag is when they've been turned into infinite non-breaking loops that keep on recurring & recurring & recurring. Either that, or something that has to sort through a large list or maybe a map generator.