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:
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)]
|