ID:155376
Jul 20 2011, 8:30 pm
|
|
Someone mind explaining how to add a cool down to an ability?
|
In response to Avainer1
|
|
Using "if(somevar == 1") or "if(somevar == 0)" to check if a variable is enabled/disabled is bulky and unreliable. Let's say, "somevar" becomes null as disabled state, then "if(somevar == 0)" will not recognize somevar as disabled.
It's much better to write "if(somevar)" for checking if enabled, and "if(!somevar)" for checking if disabled. "if(!somevar)" will recognize both 0 and null as disabled. Secondly: sleep(50) does not sleep for 50 seconds, it sleeps for 50 ticks, which is 5 seconds. Third, the second if() statement should be an else-clause. And it really doesn't need that <font color="blue">return</font> there. Oh, not to mention you are using the " == " operator in cases where " = " should be used. mob |
In response to Nielz
|
|
Secondly: sleep(50) does not sleep for 50 seconds, it sleeps for 50 ticks, which is 5 seconds. whats better sleep() or spawn() and how can you tell ticks to seconds like 50 ticks = 5 secs so 100 ticks = 10 secs < right or wrong how does the math work so a person can get it right with ticks to seconds |
In response to Distant Star Corporation
|
|
That depends... "spawned" code will continue to be executed even after the parent proc/verb ended. It's used to "spawn code out of a verb/proc". spawn() is also used to delay code without holding up the code that comes after the code that was "spawned".
And 1 tick is 1/10 second. |
In response to Nielz
|
|
Actually i already solved this problem about 10mins after i posted this, i just forgot to say so, but thanks anyways. Did what your already telling me to do.
|
In response to Distant Star Corporation
|
|
Yes, you are right. So Sleep(500) = 50Seconds. Spawn is better.
|
In response to Dimetri
|
|
spawn() is not better, there is no "better" between spawn() and sleep(). They both have different functions.
|
In response to LordAndrew
|
|
sleep() will keep the proc in play which i assume accumulates more resources than oppose to spawn()
so yes, it is better in this scenario if that is the case |
In response to Towers
|
|
No. sleep() stops a proc until the timer runs out, spawn() performs an action at the end of the timer while allowing the proc to continue. They serve 2 completely different purposes and neither is better than the other BECAUSE they serve completely different purposes. Neither uses any more resources than the other, as they don't inherently perform any actions, they simply delay actions.
|
In response to Robertbanks2
|
|
Robertbanks2 wrote:
No. sleep() stops a proc until the timer runs out, spawn() performs an action at the end of the timer while allowing the proc to continue. They serve 2 completely different purposes and neither is better than the other BECAUSE they serve completely different purposes. i hope that wasnt directed at me, because thats exactly what i said but sleep() causes the proc to pause, and i assume itd use less resources if it the proc ended instead which would be achieve by using spawn() |
In response to Towers
|
|
I actually tacked onto the end after posting, "Neither uses any more resources than the other, as they don't inherently perform any actions, they simply delay actions." Keeping a proc running has no tangible effect on resources if it isn't doing anything, and both require that the proc continue running until it returns anyway.
And no, it was directed at everyone in the discussion of whether one is better than the other. |
In response to Robertbanks2
|
|
Robertbanks2 wrote:
I actually tacked onto the end after posting, "Neither uses any more resources than the other, as they don't inherently perform any actions, they simply delay actions." Keeping a proc running has no tangible effect on resources if it isn't doing anything, and both require that the proc continue running until it returns anyway. not if you use spawn(), then the proc would return without the delay |
In response to Towers
|
|
So spawning off a second proc to decrement a variable is more resource friendly than keeping the original proc when all it has left to do is decrement a variable? As I said, there is no difference, removing the original proc requires that, should something need to be done afterwards, another proc be created(the spawn()) to handle that action.
|
In response to Robertbanks2
|
|
humph
|
You first need to add a var, for the cooldown. Like lets say you are adding Kamehameha?