A command calls a script which should run only once until it is finished. It should not be called until it is finished. How can I make a query so that a command does not overlap?
Here's my approach: we create a global variable to store the the function's state (locked/unlocked) and based on that the function can continue it's execution or halt it so you have only one instance running at any given time even if function is called multiple times within a small time frame.
proc something {your arguments in here} {
global lock
if {$lock} {
# function was previously called and it's now in a locked state, so we halt the further code execution
return
} else {
# function isn't locked so we first make sure we lock it and then continue with the execution of the code
set lock 1
}
# execute this code only once
# when finished we unlock it so can be called again when needed but once per instance
set lock 0
}
Once the game is over, the king and the pawn go back in the same box.