ID:793976
Jun 2 2012, 8:19 pm (Edited on Jun 3 2012, 6:27 pm)
(See the best response by Forum_account.)
|
|
Hello Can anyone give me an example of what should I use to add some cooldown to the techniques/attack on a demo I'm making?
|
whats the x for? sorry for the question don't know what it is and got undefined var
|
for(var/x in cooldowns)
It just tells for() to search every entry in cooldowns, and that you'll be referencing it somewhere in the loop. You might need to change x-- and if(!x) to cooldowns[x]-- and if(!cooldowns[x]), but my sleep deprived brain didn't consider it last night. |
mob No errors but if i add the last line I can only use the verb once anyone know whats causing this or what should i do? |
You need to spawn()-off the Timer() process in Cooldowns/New(), otherwise they never decrease.
Don't forget the fixes Robertbanks2 mentioned in post #4 (made my second comment irrelevant) |
He does, but the issue at hand is that it wasn't meant to be copy pasted in. He shouldn't have TRIED to copy paste it in(which he obviously did). Andy, I suggest you try actually looking through the code to understand the logic behind it, rather than just mashing it into your game and hoping that everything works.
AFAIK, there's no difference in efficiency between using continue and just putting everything under the if(), so it's just a matter of preference. I like it that way because it helps prevent over-indentation when you need to add a bunch of things without having a ridiculously long if() check. Also, I'm not really sure why I thought if(x!>0) would work at the time. I should probably stop answering questions at 3am. |
Here's some code I wrote last night for the Action RPG Framework to handle cooldowns. It's a slightly different approach:
mob You'd do something like this to use it: mob Instead of having a periodic event to reduce the remaining time for each cooldown, this just remembers the time when each cooldown will stop. It's not necessarily better (though it's quite limiting to only allow whole second cooldowns), though if you don't need to have a periodic event it's best to avoid it. |
In response to Forum_account
|
|
I'm not sure if there's much of a difference in efficiency, but on_cooldown() can probably just return if cooldowns[] is null or empty.
|
In response to Forum_account
|
|
Awesome. I didn't even know you could manipulate world.time like that, or that you could reference arguments that weren't specifically defined. The more you know.
|
In response to Kaiochao
|
|
Kaiochao wrote:
I'm not sure if there's much of a difference in efficiency, but on_cooldown() can probably just return if cooldowns[] is null or empty. It doesn't remove entries from the list after the cooldown has expired. It just always checks the time. |
In response to Forum_account
|
|
Haha, sorry! I completely forgot why I referred you to that design.
|
Hopefully I didn't butcher that, I didn't test anything in the compiler, but that's about how you want to handle it.
You could use a list in the mob as well, but getting used to using datums for this kind of thing is pretty helpful, and you would probably use a datum to handle all of your timed effects like debuffs, buffs, cooldowns, quest time limits, etc anyway, so having it in place could save you time and effort later on.