Register forum user name Search FAQ

Gammon Forum

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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ OnPluginPartialLine from python

OnPluginPartialLine from python

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


Posted by Worlo   Netherlands  (7 posts)  Bio
Date Wed 05 Dec 2007 02:20 PM (UTC)
Message
I am unable to get OnPluginPartialLine to work from python.

This is what I looked at first:
http://www.gammon.com.au/forum/bbshowpost.php?id=3774&page=2

But my VBScript knowledge just isn't good enough to get what I want.

I want to do something like:

import re

def OnPluginPartialLine(txt):
    if re.match("^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)w (.*)-", txt):
        <do some work>


Putting a world.Note("Plugin Match Found") there causes errors in my plugin. I get a pop-up saying Type Mismatch. But i have no idea what line the type mismatch is on. My hunch is that this is not a function in VB, so it must be something different to use in Python, but I have no clue.

Here is the code for my plugin at the moment:

<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE muclient>

<!-- Plugin "Status_Bar_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Prompt_Handler"
   author="Worlo"
   id="ff9331b06c15ab21046be001"
   language="Python"
   purpose="Get prompt info in variables as it arrives."
   date_written="2007-12-05 16:00:00"
   requires="4.14"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
import re

def OnPluginPartialLine(txt):
    if re.match("^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)w (.*)-", txt):
        world.Note("Plugin Match Found")

]]>
</script>

</muclient>


Who can enlighten me?

Warm regards, Worlo
Top

Posted by Nick Gammon   Australia  (23,132 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 05 Dec 2007 07:02 PM (UTC)
Message
See:

http://www.gammon.com.au/forum/bbshowpost.php?id=5110

I think it is something to do with the default return type that Python must use.

As far as I can tell, you must either return nothing - that is, the empty variant (however you do that in Python) or something that can be converted to a number. However that number is not used in this case.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Isthiriel   (113 posts)  Bio
Date Reply #2 on Thu 06 Dec 2007 02:56 AM (UTC)
Message
Omitting the return at the end of the function is the same as specifying "return None". (Which should be the translation of 'empty variant'.)

Top

Posted by Worlo   Netherlands  (7 posts)  Bio
Date Reply #3 on Thu 06 Dec 2007 05:54 AM (UTC)
Message
Thanks, the return True is what you need.


So the updated script function that is matching all prompts right when they arrive perfectly is:


<script>
<![CDATA[
import re
def OnPluginPartialLine(txt):
    if re.match("^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)w (.*)-", txt):
        world.Note("Plugin Match Found")
    return True
]]>
</script>
Top

Posted by Worlo   Netherlands  (7 posts)  Bio
Date Reply #4 on Thu 06 Dec 2007 06:57 AM (UTC)
Message
Here is my finalized plugin that captures prompt information into variables for Achaea, use it as you please.


<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE muclient>

<!-- Plugin "Status_Bar_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Prompt_Handler"
   author="Worlo"
   id="ff9331b06c15ab21046be001"
   language="Python"
   purpose="Get prompt info in variables as it arrives."
   date_written="2007-12-05 16:00:00"
   requires="4.14"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
import re
def OnPluginPartialLine(txt):
    matchObject = re.match("^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)w (.*)-", txt)
    if matchObject:
        groups = matchObject.groups()
        # uncomment the following to see if you are matching
        # world.Note("H: " + groups[0])
        health = groups[0]
        mana = groups[1]
        endurance = groups[2]
        willpower = groups[3]
        statusFlags = groups[4]
        world.SetVariable("health", health)
        world.SetVariable("mana", mana)
        world.SetVariable("endurance", endurance)
        world.SetVariable("willpower", willpower)
        world.SetVariable("statusFlags", statusFlags)
    return True
]]>
</script>

</muclient>
Top

Posted by Worlo   Netherlands  (7 posts)  Bio
Date Reply #5 on Thu 06 Dec 2007 02:02 PM (UTC)
Message
So I noticed world variables are contained in the plugin...

I want reliable information sharing across tools so I did a database thing.

This is my plugin now.

<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE muclient>

<!-- Plugin "Status_Bar_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Prompt_Handler"
   author="Worlo"
   id="ff9331b06c15ab21046be001"
   language="Python"
   purpose="Get prompt info in variables as it arrives."
   date_written="2007-12-05 16:00:00"
   requires="4.14"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
import re
from pysqlite2 import dbapi2 as sqlite

def setStatusValues(health, mana, endurance, willpower, statusFlags):
    con = sqlite.connect("c:\achaea\achaea.db")
    cursor = con.cursor()
    array = {'health': health,
             'mana': mana,
             'endurance': endurance,
             'willpower': willpower,
             'statusFlags': statusFlags}
    for key, value in array.iteritems():
        cursor.execute("update status set statusValue = '%s' where statusName = '%s'" % (value, key))
    cursor.close()
    con.commit()
    con.close()

def OnPluginPartialLine(txt):
    matchObject = re.match("^([0-9]+)h, ([0-9]+)m, ([0-9]+)e, ([0-9]+)w (.*)-", txt)
    if matchObject:
        groups = matchObject.groups()
        # uncomment the following to see if you are matching
        # world.Note("H: " + groups[0])
        health = groups[0]
        mana = groups[1]
        endurance = groups[2]
        willpower = groups[3]
        statusFlags = groups[4]
        setStatusValues(health, mana, endurance, willpower, statusFlags)
    return True
]]>
</script>

</muclient>


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.


20,018 views.

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

Go to topic:           Search the forum


[Go to top] top

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