Calling OnPluginPartialLine from Python

Posted by Tom Geudens on Wed 05 Jan 2005 06:15 PM — 5 posts, 23,209 views.

#0
Greetings all,
I'm a beginner in all this (this being MUSHclient, plugins/scripting and Python). I was trying to rewrite a couple of the VBscripts in Python ... and most of them go well, but I failed with the OnPluginPartialLine ...

I wrote the following :
import re
def OnPluginPartialLine(sText):
world.InfoClear ()
world.Info ("Before Compile - ")
myregexp = re.compile("^(.*?)h\, (.*?)m\ ex(.*?)\-$")
world.Info ("After Compile ")
mymatch = myregexp.match(str(sText))

And wanted to build on that ...
However, I'm getting Type Mismatch errors for every
line the MUD (Lusternia) is giving me.

Can anyone help me out here ?
Regards,
Tom

P.S. My apologies if this has already been covered
somewhere, I've read several scripts but found no-one
that called OnPluginPartialLine from Python.
Australia Forum Administrator #1
Does the compile fail, or the match?
#2
Well, actually it gives me trouble whatever I put
in the function, including when I leave out the
mymatch = myregexp.match(str(sText))

What I'm trying to accomplish (if it isn't obvious :-)
is that triggers would fire on my MUDprompt (which
looks like 3093h, 2580m, 2238e, 10p ex-)without
waiting for the carriage return. I've found several
scripts that could possibly accomplish this on the
forums (and at the moment I'm checking the one you
wrote in LUA with the OnPluginPacketReceived function)
but I'm having no success converting them to Python.

Regards,
Tom Geudens
Australia Forum Administrator #3
What I suggest you do is use the Lua plugin, or a variant, that simply has the job of adding the newline. All you need to do is get the regexp right for your prompt.

Then you can write a normal trigger, in Python or any other language, to process the prompt. The Lua plugin simply makes the trigger fire immediately by adding the newline.
Russia #4
I used to have the same problem and it turned out to be easy to solve. Apparently Python's COM bindings are acting up, not sure what exactly the problem is, but it seems to be caused by Python automatically returning some value on each call to OnPluginPartialLine and Mushclient or COM, or something out there, expecting a different type of value. Anyways, the easy solution is to make sure that OnPluginPartialLine ALWAYS returns True (or False if that makes sense). Just make sure that you have a "return True" statement at every potential exit from the function and you'll be okay.