egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

finishing script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
haferbrei
Voice


Joined: 08 Apr 2020
Posts: 21

PostPosted: Sat Feb 27, 2021 5:35 am    Post subject: finishing script Reply with quote

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?
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3733
Location: Mint Factory

PostPosted: Sat Feb 27, 2021 7:09 am    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber