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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  My first plugin in python, how can I make it prettier?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: My first plugin in python, how can I make it prettier?
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Sat 30 Oct 2004 11:53 PM (UTC)  quote  ]
Message
If you have loggged into the forum, you should be able to click the "Edit" button to correct a post.

I have done it for you, the word [code] is case-sensitive, and then you should "quote forum codes" which is an option in the MUSHclient notepad, to put backslashes in front of square brackets and backslashes themselves.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Sat 30 Oct 2004 11:15 PM (UTC)  quote  ]
Message
Crap I really screwed that post up, but I hope you get the idea. I can't figure out how to edit it.
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Sat 30 Oct 2004 11:10 PM (UTC)  quote  ]

Amended on Sat 30 Oct 2004 11:51 PM (UTC) by Nick Gammon

Message
I just started with python a couple weeks ago and managed to rewrite my OnPluginPartialLine in it. But this is the meat of the first complete plugin I made that is all-inclusive. It works the way it is, but I wanted to ask everyone's expert opinions on what I could have done better. Any input is appreciated. I am working on more critical tasks and am sometimes at a loss of how to script something in python. How could I make this plugin more efficient? How much useless or extra code do I have? What would you do to improve this? Thanks in advance for everyone's more experienced input.
<trigger
   enabled="y"
   group="fishing"
   match="^([0-9]+h, [0-9]+m(, [0-9]+(w|e)(, [0-9]+(w|e)|)|) [cexkdb]+\-|)You reel in the last bit of line.*$"
   name="bait_hook_1"
   regexp="y"
   script="CreateAction"
   sequence="100"
   ></trigger>
<trigger
   enabled="y"
   group="fishing"
   match="^([0-9]+h, [0-9]+m(, [0-9]+(w|e)(, [0-9]+(w|e)|)|) [cexkdb]+\-|)With a final tug\, you finish reeling in the line and land a.*$"
   name="bait_hook_2"
   regexp="y"
   script="CreateAction"
   sequence="100"
></trigger>
<trigger
   enabled="y"
   group="fishing"
   match="^You feel a fish nibbling on your hook\.$"
   name="tease_line_1"
   regexp="y"
   script="CreateAction"
   sequence="100"
></trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="^([0-9]+h, [0-9]+m(, [0-9]+(w|e)(, [0-9]+(w|e)|)|) [cexkdb]+\-|)You quickly jerk back your fishing pole and feel the line go taut\. You\'ve hooked$"
   name="reel_line_3"
   regexp="y"
   script="CreateAction"
   sequence="100"
  ></trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="Relaxing the tension on your line you are able to reel again."
   name="reel_line_2"
   sequence="100"
  >
  <send>reel line</send>
  </trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="^You see the water ripple as a fish makes a medium strike at your bait\.$"
   name="jerk_line_1"
   regexp="y"
   script="CreateAction"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="^You stagger as a fish makes a large strike at your bait\.$"
   name="jerk_line_2"
   regexp="y"
   script="CreateAction"
   sequence="100"
  ></trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="^You feel a fish make a small strike at your bait\.$"
   name="jerk_line_3"
   regexp="y"
   script="CreateAction"
   sequence="100"
  ></trigger>
  <trigger
   enabled="y"
   group="fishing"
   match="^You feel a fish make a medium strike at your bait\.$"
   name="jerk_line_4"
   regexp="y"
   script="CreateAction"
   sequence="100"
  ></trigger>
   <trigger
   enabled="y"
   group="fishing"
   match="^You quickly jerk back your fishing pole\, to no avail\.$"
   regexp="y"
   script="CreateAction"
   sequence="100"
  >
  </trigger>
 <trigger
   enabled="y"
   group="fishing"
   match="^a (large|small|good\-sized) one\!$"
   name="reel_line_1"
   regexp="y"
   script="CreateAction"
   sequence="100"
  >
  </trigger>
<trigger
   enabled="y"
   group="fishing"
   match="^You have recovered balance on all limbs\.$"
   regexp="y"
   script="OnBalance"
   sequence="100"
   >
  </trigger>
<aliases>
  <alias
   name="switch_fishing"
   script="Switch"
   match="^fish(on|off)(n|ne|e|se|s|sw|w|nw|)$"
   enabled="y"
   expand_variables="y"
   group="fishing"
   regexp="y"
   sequence="100"
  >
  </alias>
  <alias
   name="bait_hook_1"
   match="^bh$"
   enabled="y"
   group="fishing"
   regexp="y"
   sequence="100"
  >
  <send>bait hook with bait</send>
  </alias>
</aliases>
balance=[1]
ActionCount=0
Direction=[]
Action=[]
def Switch(name, output, wildcards):
    global Direction
    if wildcards[0]=='on':
        #wield pole, bait and cast? turn on triggs etc
        #set direction with wildcards[1]: syntax fishon east
        world.EnableTriggerGroup("fishing", 1)
        world.Execute ("uwa")#unwield all
        world.Send ("wield pole")
        Direction=wildcards[1]#need to send cast and Direction to Action?
        CreateAction("bait_hook","blah","blah")
    elif wildcards[0]=='off':
        #turn off triggs, reel in, remove bait, unwield pole
        world.EnableTriggerGroup("fishing", 0)
        world.send("reel line")
        world.send("get bait from pole")
        world.send("unwield pole")

def OnBalance(name, output, wildcards):#balance taken at jerk, tease, bait, cast
    global balance
    balance=[1]
    DoAction()#got balance, now do whatever is needed

    
def DoAction():#here I need to bait, cast, tease, jerk and reel
    #need counter to do jerk and tease 3 times, 
    global ActionCount, Action, balance
    if Action:
        if cmp('bait hook',Action)==0:
            world.execute("bh")
            Action=('cast line '+Direction)
        elif Action==('cast line '+Direction):
            world.send(Action)
            Action=[]
        elif Action=='reel line':
            world.send(Action)
        else:
            if ActionCount >= 3:
                ActionCount = 0
                Action=[]
            elif ActionCount < 3:
                world.Send(Action)
                ActionCount = ActionCount+1
                balance=[]
                
def CreateAction(name, output, wildcards):# is this needed?
    global Action, ActionCount, balance#delimit the action names and send to appropriate
    if name:
        Action=" ".join(name.split('_')[:2])
        ActionCount=0
        if balance:
            DoAction()        
    else:
        return True

    
[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.


2,063 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]