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 ➜ Python ➜ My first plugin in python, how can I make it prettier?

My first plugin in python, how can I make it prettier?

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


Posted by Somegirl   (33 posts)  Bio
Date Sat 30 Oct 2004 11:10 PM (UTC)

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

    
Top

Posted by Somegirl   (33 posts)  Bio
Date Reply #1 on Sat 30 Oct 2004 11:15 PM (UTC)
Message
Crap I really screwed that post up, but I hope you get the idea. I can't figure out how to edit it.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 30 Oct 2004 11:53 PM (UTC)
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
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.


12,451 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.