Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ General
➜ #wait in MUSHclient by python
#wait in MUSHclient by python
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zero
(5 posts) Bio
|
Date
| Wed 29 Jul 2009 11:04 PM (UTC) |
Message
| I wrote a "#wait" like zmud for MUSH:
def foo():
ExecAfter(2, lambda:world.send('next'))
def localfunc():
world.send('next')
ExecAfter(1, localfunc)
funclist = {}
def ExecAfter(time, func):
global funclist
i = 0
if not funclist.has_key(func):
i = len(funclist)
funclist[func] = i
else:
i = funclist[func]
world.DoAfterSpecial(time, 'CallBack(%d)' %i)
def CallBack(i):
func = None
for item in funclist.iteritems():
if item[1] == i:
print item[0]()
return | Top |
|
Posted by
| Zero
(5 posts) Bio
|
Date
| Reply #1 on Wed 29 Jul 2009 11:38 PM (UTC) |
Message
| Usage: (same as "#wait 2000;next" in zMud)
<trigger ...>
<send> ExecAfter(2, lambda:world.send('next')) </send>
</trigger>
<script>
funclist = {}
def ExecAfter(time, func):
global funclist
i = 0
if not funclist.has_key(func):
i = len(funclist)
funclist[func] = i
else:
i = funclist[func]
world.DoAfterSpecial(time, 'CallBack(%d)' %i)
def CallBack(i):
func = None
for item in funclist.iteritems():
if item[1] == i:
print item[0]()
return
</script> | Top |
|
Posted by
| Rakon
USA (123 posts) Bio
|
Date
| Reply #2 on Fri 31 Jul 2009 08:41 PM (UTC) |
Message
| For future reference, you can use the built-in function DoAfter, or DoAfterSpecial for MUSHclient.
http://www.gammon.com.au/scripts/function.php?name=DoAfter
http://www.gammon.com.au/scripts/function.php?name=DoAfterSpecial
If you are wanting to pause the python scripting (I'd advise using the MUSHclient function above instead, as the following will pause the entire script) use :
import time as time
print 'Waiting two seconds...'
time.sleep(2)
print 'Two seconds is up!'
Again, that will pause the entire script, probably not what you want. Use MUSH funtion 'DoAfter' and 'DoAfterSpecial'.
|
Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for. | Top |
|
Posted by
| Zero
(5 posts) Bio
|
Date
| Reply #3 on Sat 01 Aug 2009 12:22 AM (UTC) Amended on Sat 01 Aug 2009 12:32 AM (UTC) by Zero
|
Message
| time.sleep(2) will cause Mushclient GUI to not respond.
I guess the GUI and scripts are in the same one thread, is it right?
So i use callback function to implement #wait. It's a wrapping function of DoAfterSpecial. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sat 01 Aug 2009 01:33 AM (UTC) |
Message
|
Quote:
I guess the GUI and scripts are in the same one thread, is it right?
MUSHclient is mainly a single thread. The MFC libraries implement dialog boxes in another thread, I think, which is why you see text scrolling by even while you are working on the GUI dialogs. Also there is another thread which monitors the script file changing.
But basically it is a single thread, to all intents and purposes.
Let me quote from the SQLite database engine FAQ page:
Threads are evil. Avoid them.
http://www.sqlite.org/faq.html
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #5 on Sat 01 Aug 2009 07:15 AM (UTC) |
Message
| It's most likely the same thread. The reason other windows still get updated is due to the message loop - it merely dispatches the messages to the right window and through those means they still get processed.
[/random post] | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
23,208 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top