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 ➜ MUSH throws an error when I try to enable scripting

MUSH throws an error when I try to enable scripting

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


Posted by Drakonik   (20 posts)  Bio
Date Wed 02 May 2007 10:52 PM (UTC)
Message
Here's the error I get: http://img123.imageshack.us/img123/8893/errorlv1.png

I don't know if I missed some step in the installation, but I'd like to finally get scripting working. Thanks in advance.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 03 May 2007 12:54 AM (UTC)
Message
This question comes up a few times, so I have amended the FAQ to handle it. See:

http://mushclient.com/faq -- point 42

Also see this forum posting:

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

- Nick Gammon

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

Posted by Drakonik   (20 posts)  Bio
Date Reply #2 on Fri 04 May 2007 12:48 AM (UTC)
Message
Everything works now, but I've got one last question.

I know how to use triggers or aliases to pass things to a script. I just don't know how to access those inside my script.

I'm planning on using the %0 to pass the whole trigger line to my script. I don't know how to take the contents of %0 and store them in some variable in my Python.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 04 May 2007 04:16 AM (UTC)
Message
Take a look at the file exampscript.pys that comes with MUSHclient - that shows accessing wildcards in Python.

- Nick Gammon

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

Posted by Drakonik   (20 posts)  Bio
Date Reply #4 on Sat 19 May 2007 04:52 AM (UTC)
Message
I'm confused now. I've looked through the example script file, and it's got an example function doing essentially what I want, but nowhere in the whole file are the variables defined. Understandably, the client pukes when I try to run the function from my trigger.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Sat 19 May 2007 04:55 AM (UTC)
Message
What is the function you are running, and what is the error message?

- Nick Gammon

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

Posted by Drakonik   (20 posts)  Bio
Date Reply #6 on Sat 19 May 2007 06:02 AM (UTC)

Amended on Sat 19 May 2007 04:39 PM (UTC) by Drakonik

Message
I'm using a trigger to catch a line of text, and trying to get the ExampleTrigger from the very bottom of the example script page to print out the line it caught.

When I try to run it, it tells me that the variables aren't defined.

Edit: Also, I was wondering if there was some way I could put a forced wait into my aliases. Can I make an alias that will 'prepare spell\n wait three second\n Cast spell' without having to resort to using an external scripting language?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Sun 20 May 2007 07:01 AM (UTC)
Message
Quote:

Can I make an alias that will 'prepare spell\n wait three second\n Cast spell'


Have you read the FAQ? ...

http://mushclient.com/faq , item 25

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Mon 21 May 2007 01:06 AM (UTC)
Message
I loaded up the example file and got no error. I can't help you if you don't copy and paste the actual error message.

- Nick Gammon

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

Posted by Isthiriel   (113 posts)  Bio
Date Reply #9 on Tue 22 May 2007 07:42 AM (UTC)

Amended on Mon 28 May 2007 06:44 AM (UTC) by Isthiriel

Message
From reading this thread I think what Drakonik is doing is creating the alias/trigger as Send to: Script and putting the function call in the Send box (complete with the variables as named in ExampScript.pys).

What he wants to do is either keep the Send to: Script setting, leave the Script box at the bottom of the dialog empty and then fill the Send box in with the name of the function he wants to call, passing the % variables in quotes (as the Send box does direct substitution).

So the Send box should contain something like:
MyScriptFunction("""%0""")


I use the """ quotes as direct substitution means if I used ' or " and %0 has a ' or " in it then Bad Things will happen.

OR, ALTERNATIVELY: (And this is what I'd recommend)
Ignore the Send to: setting, leave the Send box completely blank and fill the Script box with the name (and just the name, no parentheses, no variable names) of the function you want called with the alias/trigger fires. This means, the example should have:
ExampleTrigger

in the Script box and nothing else.

Drakonik, my ExampScript.pys has:
def ExampleTrigger (thename, theoutput, wildcards):
  world.note ("Trigger " + thename + " fired.");
  world.note ("Matching line was: " + theoutput);
  for i in range (10):
    if wildcards [ i ]:
       world.note ("Wildcard " + str(i) + " = " + wildcards [ i ])

The "def" means we are defining a function, that happens to be named "ExampleTrigger". It takes exactly three arguments. The first line also tells us that whatever is actually passed to the function, the first argument should be accessible to the code within the function under the name: "thename", the second: "theoutput" and the third: "wildcards".

Those three variable names could be anything because they only have scope from the "def" until we reach the same indentation level in the file (that would be the line after what I pasted above).

For example:
def ExampleTrigger(n, o, w):

is equally valid but less useful as we don't have as much information about what we should pass to ExampleTrigger. Though in this case ExampleTrigger is actually being called from the MUSHclient main C++ thread, which will always pass the name of the trigger that matched, the last line that matched and the contents of the wildcards in the match-phrase.

If we wanted to call ExampleTrigger ourselves, we'd put on a line by itself (appropriately indented):
    ExampleTrigger("SomeRandomTrigger", "This is an example line of text that ExampleTrigger thinks we just matched.", [])


I don't know if I can elaborate further than that?

BTW, Nick, one of the reasons I love Python is that there are so many ways to do simple things. I started out thinking there had to be an easier way of writing the last three lines of ExampleTrigger, and ended up with:
    [world.Note("Wildcard %d = %s" % (i, w)) for i, w in dict(zip(range(1, len(wildcards)), wildcards[1:])).iteritems() if w]

Which works, but doesn't cover "easier" or "simpler" :D

If you ignore the number, you can get away with:
    [world.Note("Wildcard = %s" % el) for el in wildcards]

OR, for really raw output (no prefixes):
    world.Note("\n".join(wildcards))

In practise I'd enclose the actual wildcard data in repr()s to be sure a blank line was an '' rather than " " or "\n".
    world.Note("\n".join([repr(el) for el in wildcards]))


EDIT: Bah. Yet Again the Python designers are one step ahead of me :)
    [world.Note("Wildcard %d = %s" % en) for en in enumerate(wildcards)]
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.


30,839 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.