ID:1883532
 
(See the best response by Mar big.)
Code:
verb
DelayTest()
var
ondelay
if(ondelay == 1)
usr << "On Delay"
else
ondelay = 1
sleep(50)
ondelay = 0


Problem description:

I'm trying to create a localized delay for separate verbs by creating the delay variable in the verbs. However, if I understand correctly, each time I use the verb the variables are reset to the default value of 0. This, of course, results in the entire verb not working as intended. I'm here to ask how I could successfully implement a delay system without having to include a global delay variable for EVERY verb I code into the game.
There's different ways you can do this. First... is the delay global, a set amount that doesn't change, or specific to certain players/events?

What do you want the delay to accomplish? Is this something that you want to wait X time and then run a proc, or change a variable/path, or output data?

An example would be:
mob
var
tmp
digging // This will be a temporary /mob variable to make sure they can't run dig, then dig again.
dig_speed = 60 // This is the delay until they can dig again, in ticks.
verb
dig()
if(!src.digging) // If the player isn't digging yet.
src.digging = 1 // They begin digging.
src << "Digging!" // Let's tell the player they are digging.
sleep(dig_speed) // Start a delay based on the player's dig_speed.
src << "Digging over!" // Let's tell the player they stopped digging.
src.digging = 0 // They stop digging.
else // If the player is already digging.
src << "Still digging!" // Let's tell the player they are already digging.
I wish to make it so that the delay applies to only the verb it is found in. For example, say I have 2 verbs: Strong Punch and Strong Kick. When I use Strong Punch, I want the delay to keep me from using Strong Punch again until oh-so-much time has passed. But I don't want the delay for Strong Punch to affect Strong Kick, and vice-versa.
In response to Lawpiecla1
So, you'll want something along these lines:
mob
var
tmp
punching
kicking
delay_punch = 60
delay_kick = 60
verb
kick()
spawn() src.delay_attack("kick")
punch()
spawn() src.delay_attack("punch")
proc
delay_attack(action)
switch(action)
if("punch")
if(!src.punching)
src.punching = 1
src << "Punch!"
sleep(src.delay_punch)
src.punching = 0
src << "Finished Punch!"
else
src << "Already Punching!"
if("kick")
if(!src.kicking)
src.kicking = 1
src << "Kick!"
sleep(src.delay_kick)
src.kicking = 0
src << "Finished Kick!"
else
src << "Already Kicking!"

Just as an example.
As you can see, Lawpiecla1, there's a lot of repeated code in these examples. It would be best for you to not copy/paste this code, and find a way to generalize your cooldown system to work with any number of actions, perhaps through the use of associative lists. There are better examples of "cooldown" systems on these forums that you can search for.
Best response
You never want to use if(somevar==1) to check if a var is true.
//To check if a var is true
if(somevar)
//if you wanted to know if it was false
if(!somevar)

I assume you want to create some type of delay system, where you don’t have to create a new var for each verb. To do this you are going to want to use a list and some helper functions.
var/tmp/list/delays
set_delay(delay,duration)
//check to see if delays is initialized
if(!delays)
//initialize delays if it wasn't
delays = list()
//create a delay in an associated list
// they are in the form of key value pairs.
delays[delay] = world.time + duration

on_delay(delay)
if(!delays)
delays = list()
//check to see if the delay is still on delay.
if(delays[delay] > world.time)
return 1

return 0
<dm>


To use it you would do something like this
verb
DelayTest()
if(on_delay("DelayTest"))
usr << "On Delay"
return
set_delay("DelayTest",50)

While I'm sure his intentions were pure, I don't think Max's example is sufficient learning material; there are some questionable practices in his snippet that I don't think should be taught to newcomers (e.g. bulky use of variables).

So, I'm going to go ahead and post mine so you can see the difference.

#define STRONG_PUNCH "Strong Punch"
#define STRONG_KICK "Strong Kick"

mob
var
tmp/list/cooldowns

verb
strong_punch()
if(!can_activate(STRONG_PUNCH))
return

// perform strong punch action here..

add_cooldown(STRONG_PUNCH, 10)

strong_kick()
if(!can_activate(STRONG_KICK))
return

// perform strong kick action here..

add_cooldown(STRONG_KICK, 15)

proc
can_activate(id)
if(has_cooldown(id))
var/cooldown_remaining = round((cooldowns[id] - world.time) / 60)
src << "[id] is currently on cooldown! ([cooldown_remaining] minutes left)"
return 0
return 1

add_cooldown(id, time)
if(!id || time <= 0) return

if(!cooldowns)
cooldowns = list()

cooldowns[id] = world.time + time

spawn(time)
if(!cooldowns || !cooldowns[id]) return

remove_cooldown(id)

remove_cooldown(id)
if(has_cooldown(id))
cooldowns -= id
if(!cooldowns)
cooldowns = null

has_cooldown(id)
return (cooldowns && cooldowns[id])


It's pretty self-explanatory looking at it. Of course, feel free to ask questions should you have any.

Edit: Kaio and Mar Big were faster. My vote goes to the latter since he wrote virtually the same example as me.
In response to FKI
FKI's version will save you more memory in the long run, since he actually set the cooldowns list to null, when they are empty.
Mar's version avoids spawn, which is good to avoid. However, initializing the list in the check is unnecessary; if the list doesn't exist, the cooldown definitely isn't active.