[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  #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] Refresh page


Posted by Zero   (5 posts)  [Biography] 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
[Go to top] top

Posted by Zero   (5 posts)  [Biography] 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>
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] 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.
[Go to top] top

Posted by Zero   (5 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] 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]
[Go to top] 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.


21,249 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]