SetTriggerOption/GetTriggerOption "name" option doesn't work

Posted by Icewolf on Mon 10 May 2010 11:26 PM — 7 posts, 29,151 views.

#0
world.GetTriggerOption("bla", "name") # always return None

world.SetTriggerOption("bla", "name", "bla") # return 30025

My MC version:4.43

Python version: 2.6
USA #1
It's not a Python issue, it's a general API issue. And it's not an issue at all according to Nick:

http://www.gammon.com.au/forum/?id=10069
Australia Forum Administrator #2
Icewolf said:

world.GetTriggerOption("bla", "name") # always return None


The name is "bla" - you don't need to query it.


Icewolf said:

world.SetTriggerOption("bla", "name", "bla") # return 30025


You can't rename triggers. The name is the key. Changing the name changes the key, effectively turning it into a different trigger. You need to delete it and re-add it, if that is what you want to do. See ExportXML and ImportXML.
#3
Nick Gammon said:

Icewolf said:

world.GetTriggerOption("bla", "name") # always return None


The name is "bla" - you don't need to query it.


Icewolf said:

world.SetTriggerOption("bla", "name", "bla") # return 30025


You can't rename triggers. The name is the key. Changing the name changes the key, effectively turning it into a different trigger. You need to delete it and re-add it, if that is what you want to do. See ExportXML and ImportXML.


Thanks Nick!

The XML approach is very elegant - I like it. However, one issue I am concerned with is that, according to the document, *XML() functions' return values seem not convey as much information as the Add*/Set*/Get* functions.

Is that true?
USA #4
If you're getting into tweaking trigger options at runtime, you might want to check out my Reflex library.

http://www.gammon.com.au/forum/?id=10073

There are examples of how to use it there, as well as the source so you can save it to your MUSHclient/lua/ folder and use it yourself.
Australia Forum Administrator #5
Icewolf said:

The XML approach is very elegant - I like it. However, one issue I am concerned with is that, according to the document, *XML() functions' return values seem not convey as much information as the Add*/Set*/Get* functions.


Both return whether they worked or not, one way or another. That should be enough to confirm it succeeded. In any case, exporting a trigger should be in a format guaranteed to import OK afterwards.
#6
Twisol said:

If you're getting into tweaking trigger options at runtime, you might want to check out my Reflex library.

http://www.gammon.com.au/forum/?id=10073

There are examples of how to use it there, as well as the source so you can save it to your MUSHclient/lua/ folder and use it yourself.


Yes. That looks like exactly what I'm doing in Python. I built a more "pythonic" interfaces for the trigger/alias/timer on top of mushclient's interfaces.

"Reflex" is one of the features - allows users to access mushclient items' options using dictrionaries:

trigger['anOption']


Items are created by instantiating the corresponding python classes, and using python's *keyword* argument feature:


aTrig = Trigger("aPattern", name="bla", group="bla", script="some")


As I said, some more pythonic ways are also used, too. Like decorators:


@Trigger.decorate("aPattern", name="bla", group="bla")
def call_back_function(line, name, wildcards):
  # do something
  pass


The above piece of code defines a trigger and use "call_back_function" as the "script" option of that trigger. Very convenient.

There are some other things I'm building currently. Like Gammon's "wait" module (I was inspired by the other post about Python coroutines: http://www.gammon.com.au/forum/?id=8277); Convenient logging utilities by which the normal stdout or other string streams can be directed to mushclient's notepads.

I may want to put those stuff on line so that others can test and use soon...