This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

finishing script

Help for those learning Tcl or writing their own scripts.
Post Reply
h
haferbrei
Voice
Posts: 24
Joined: Wed Apr 08, 2020 8:57 pm

finishing script

Post by haferbrei »

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?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.

Code: Select all

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.
Post Reply