ID:2476574
 
(See the best response by Kaiochao.)
Code:
/mob/laugh()
set name = "Laugh"
set desc = "Have a good time!"
set category = "IC"

var/choice = input(src, "Choose a type of laughter!") in laughter_types

(...)


Problem description: First and foremost, hello and thank you for your time. Here's my question.

Let's say I have the verb above. Upon calling it, it displays an X amount of elements (laughter_types) in a list from which the user can pick.

However, if they click it 5 times, even after selecting one, another one then another list will appear. The only method I know how to negate the spam is to add an extra var to check if they are using it, a kind of a cooldown:

/mob/laugh()
set name = "Laugh"
set desc = "Have a good time!"
set category = "IC"

if(has_laughed) // Checks for cooldown
return

var/choice = input(src, "Choose a type of laughter!") in laughter_types

if(!choice) // No cooldown if they cancelled it
return

has_laughed = TRUE // Add a cooldown we reset elsewhere

(...)


My question is - is there a method to add a check for all verbs whether that specific verb is in use by the same user? Something like:

/mob/verb
if(busy)
return

busy = 1
//do the called verb

busy = 0
Best response
The "busy" variable is a good start. It's a single variable to check whether a single verb is in use to prevent that verb from stacking. You could use that same variable in other verbs.

For more flexibility, you're asking for a way to tell if a specific verb is in use, because you want multiple different verbs to be able to queue up. As usual, going from "one" to "many" usually involves a list. Lists are variable in size, so you can store data about as many things as you want. Specifically, we can use an associative list to associate the name of the verb to its locked state.
mob
var
tmp
list/locks = new

verb
laugh()
set
name = "Laugh"
desc = "Have a good time!"
category = "IC"

// Check
if(locks["laugh"])
return

// Lock
locks["laugh"] = TRUE

// Do stuff
var choice = input(...)

// Unlock
locks -= "laugh"