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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  Help with SetTriggerOption

Help with SetTriggerOption

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


Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Mon 15 Aug 2005 07:13 AM (UTC)

Amended on Mon 15 Aug 2005 07:34 AM (UTC) by Rakon

Message
Greetings all, I am having an issue with AddTriggerEX, it seems not to suport the flag, repeat. I have right now:



def CreateList(name,output, wildcards):
	CheckName = world.IsTrigger(wildcards[0] + "List")
	world.Note(CheckName)

	
	if CheckName == 30005:
		world.SetVariable(wildcards[0], " ")
		ListName = world.GetVariable(wildcards[0])	
		trigger = ("(@!" + wildcards[0] + ")")
		
		world.AddTriggerEx (wildcards[0] + "List", trigger, "",561,wildcards[1], 0, "", "", 0, 100)
		world.ColourNote("white", "","\n" + " "*5 +  "List with name " + wildcards[0] + " created.")			
	elif CheckName == 0:
		world.ColourNote("white", "", "\n" + " "*5 + "Sorry, but the list " + wildcards[0] + " already exist. Please try another name.")
	else:
		world.ColourNote("white", "", "\n" + " "*5 + "There was an error trying to create the list, please try it agian.")
		

As you can see I have "561" for the trigger flags, is there a code number for adding "repeat", "true" to that??
or Do I need to use

world.SetTriggerOption(trigger, "repeat", "1")

Id I do need to use that syntax, what is the correct form for Python? I have tried setting the contents to "y", "Y", "1", "true", 1, and y. :D none of them seem to work.

Any advice or pointers in the correct way, would be most helpful.

--Rakon

EDIT<Reason:Darn code tags :P>

EDIT<Reason: Put replace, instaed of repeat>

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Mon 15 Aug 2005 09:52 AM (UTC)
Message
It should be:
world.SetTriggerOption(trigger, "repeat", "y")

You can find out the values, by creating a trigger how you'd like it, and then looking at its XML.

No, repeat is not a flaggable value (it doesn't have a number).

Since youre creating triggers in this manner (and they'll require two calls, create, then settriggeroption), you might think about using importXML instead.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Mon 15 Aug 2005 11:02 AM (UTC)
Message
With Python, ImportXML is pretty simple actually. You can use this class to create a Python object for the trigger:


class Trigger(object):
    def __init__(self, match, name=None, keep_evaluating=None, enabled="y", group=None,
                 send=None, script=None, sequence="100", custom_colour=None, clipboard_arg=None,
                 expand_variables=None, ignore_case=None, lines_to_match=None,
                 omit_from_log=None, omit_from_output=None, regexp=None, repeat=None, send_to=None,
                 multi_line=None):
        self.name = name
        self.match = match
        self.keep_evaluating = keep_evaluating
        self.enabled = enabled
        self.send = send
        self.script = script
        self.sequence = sequence
        self.custom_colour = custom_colour
        self.clipboard_arg = clipboard_arg
        self.expand_variables = expand_variables
        self.group = group
        self.ignore_case = ignore_case
        self.lines_to_match = lines_to_match
        self.omit_from_log = omit_from_log
        self.omit_from_output = omit_from_output
        self.regexp = regexp
        self.multi_line = multi_line
        self.repeat = repeat
        self.send_to = send_to

    def __str__(self):
        xml = "<triggers>\n<trigger\n"
        for arg in self.__dict__.keys():
            if self.__dict__[arg] is not None:
                if arg != "send":
                    xml += '  %s="%s"\n' % (arg, self.__dict__[arg])
        if self.send is not None:
            xml += "><send>%s</send>\n" % self.send
        xml += "</trigger>\n</triggers>"
        return xml


You could put that class somewhere you can import it from or just use it directly from the script, and then create triggers as Python objects, converting them to XML for world.ImportXML with a simple str() call. Like this:


        #world.AddTriggerEx (wildcards[0] + "List", trigger, "",561,wildcards[1], 0, "", "", 0, 100)
        new_trig = Trigger(trigger, name = wildcards[0]+"List", repeat="y")
        #all the rest of the options are set simply by their name instead of flags
        world.ImportXML(str(new_trig))   #imported the XML representation of the trigger object


Or you could reuse one object for creating several triggers which only differ in name and match attributes:


new_trig = Trigger("", repeat="y", expand_variables="y")  #plus all other constant options
for match,name in matches_names:
    new_trig.name = name
    new_trig.match = match
    world.ImportXML(str(new_trig))
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #3 on Mon 15 Aug 2005 07:43 PM (UTC)
Message
Or you can just create a string version of the trigger (with your variables included) (since youre inputting a trigger with all of the attributes the same, except for the name and the match text), and then import that. Like this:

ImportXML("<triggers><trigger enabled=\"y\" ignore_case=\"y\" match=\"" + Match + "\" name=\"" + Name + "\" regexp=\"y\" repeat=\"y\" sequence=\"100\"><send>" + Send + "</send></trigger></triggers>")

Or, whatever your trigger is.
(At least, I believe I've escaped those correctly)

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #4 on Mon 15 Aug 2005 07:49 PM (UTC)

Amended on Mon 15 Aug 2005 07:51 PM (UTC) by Rakon

Message
Hello agian,thank you all for responding, and Ked, that is a useful class def, thanks :D. I put it at the top of my .pys, and everything seems to work alright, however when I try to call it, it gives me the error "Match text can not be empty"
I set the alias to World.Note, what str(new_trig) is, below is the code.

def CreateList(name,output, wildcards):
	CheckName = world.IsTrigger(wildcards[0] + "List")
	world.Note(CheckName)
	trigger = ("(@!" + wildcards[0] + ")")
	new_trig = Triggers(trigger, name = wildcards[0]+"List", repeat="y",regexp="y")
	
	
	if CheckName == 30005:
		world.SetVariable(wildcards[0], " ")
		ListName = world.GetVariable(wildcards[0])	
		
		world.AddTriggerEx (wildcards[0] + "List", trigger, "",561,wildcards[1], 0, "", "", 0, 100)
		world.ColourNote("white", "","\n" + " "*5 +  "List with name " + wildcards[0] + " color, " + wildcards[1] + " created.")
        world.ImportXml(str(new_trig))
        world.note(str(new_trig))

Error raised by mush:
Must have trigger match text (trigger not loaded)

and the note produces the following,

<triggers>
<trigger>
  name="testerList"
  sequence="100"
  enabled="y"
  repeat="y"
  regexp="y"
  match="(@!tester)"
</trigger>
</triggers>

In there, the match text Is not empty, so why is ImportXml saying it is??

--Rakon

EDIT<Reason:Spelling corrections>

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #5 on Mon 15 Aug 2005 08:10 PM (UTC)

Amended on Tue 16 Aug 2005 03:10 AM (UTC) by Rakon

Message
Meh, I seemed to have found the problem.

def __str__(self):
        xml = "<triggers>\n<trigger\n"
        for arg in self.__dict__.keys():
            if self.__dict__[arg] is not None:
                if arg != "send":
                    xml += '  %s="%s"\n' % (arg, self.__dict__[arg])
        if self.send is not None:
            xml += "><send>%s</send>\n" % self.send
        xml += "\n</trigger>\n</triggers>"
        return xml


Since I have no send field, the last > to close <trigger, was not being put in, Fixed it by adding it to the next line down.

--Rakon

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #6 on Wed 17 Aug 2005 04:31 AM (UTC)

Amended on Wed 17 Aug 2005 04:47 AM (UTC) by Rakon

Message
Hello everyone. I have a simple question, that probaly has a simple answer and I still can't figure it out.
Im am trying to create a list though an Alias, and it should save it to the specified Variable. The Alias works correct, and the Script give confermation of adding the name to the list, however, when I check the Variable it is not there.Any ideas??

# This function adds a name to a user created list --Rakon
def Addit(name,output, wildcards):
	global List
	List = [world.GetVariable(wildcards[1])]# Get list to save
	AddWho = wildcards[0] #Save this name to List
    
	if AddWho in List:#Oops, already in the list.
		world.Note(" " *5 + "Sorry, but " + AddWho + " is already in that list. " + AddWho + " not added.")
		return
	elif AddWho not in List:#Not on the list, ok to add.
		List.append(AddWho)
		world.Note(str(AddWho) + " added to list " + wildcards[1])dcards[1])


Here is The alias,

<aliases>
  <alias
   script="Addit"
   match="^Add (.*?)\s(.*?)$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   sequence="100"
  >
  </alias>
</aliases>

The world note at the end of the function, is sent, but the Variable still does not contain the wildcard.
Any ideas?
--Rakon



Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #7 on Wed 17 Aug 2005 08:03 AM (UTC)
Message
MC variables can only store strings, so you wouldn't be able to store a Python list to them directly. Doing so would require pickling/unpickling the list to/from the variable, which was discussed in another thread here. But since all you want to do is just store some strings into the list you don't need to muck with pickling - the simple split/join operation will suffice to convert between a string value stored in an MC variable and a Python list object:


# This function adds a name to a user created list --Rakon
def Addit(name,output, wildcards):
    global List

    #Here we get an MC var's value (a string) and split it, presuming that is a list of values
    #separated with the '_' character
    List = world.GetVariable(wildcards[1]).split("_")
    AddWho = wildcards[0] #Save this name to List
    
    if AddWho in List: #Oops, already in the list.
        world.Note(" " *5 + "Sorry, but " + AddWho + " is already in that list. " + AddWho + " not added.")
        return
    elif AddWho not in List:#Not on the list, ok to add.
        List.append(AddWho)
        #Now we save the list back into the MC var, using '_' as a delimiter again and ensuring
        #that all items are converted to strings
        world.SetVariable(wildcards[1], "_".join([str(i) for i in List])
        world.Note(str(AddWho) + " added to list " + wildcards[1])
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #8 on Wed 17 Aug 2005 01:06 PM (UTC)
Message
Thanks Ked, but I think I may need to pickle it still, be cause I need to be able to remove a name from the list as well. Is there a simpler way of doing this, or must I tread into the pickle jar?

--Rakon

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #9 on Wed 17 Aug 2005 03:25 PM (UTC)
Message
You can remove from the list just fine the same way. It's the same sequence, aside from doing list.remove() instead of list.append():



world.SetVariable("test_var", "1_2_3")
lst = world.GetVariable("test_var").split("_")
lst.remove("2")
world.SetVariable("test_var", "_".join(lst))



So you split the string into a Python list the same way you do when adding, then you remove the value (remember that you get strings when splitting into the list, and need strings in the list when joining into the var so cast types as needed), and join the resulting list back into the var.

Pickling is only useful when you need to store "complex" Python objects persistantly (in an MC var for example), like a dictionary or a custom class instance, etc.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #10 on Wed 17 Aug 2005 03:28 PM (UTC)
Message
But if you'll need pickling still then this should cover it:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5410
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #11 on Thu 20 Oct 2005 11:25 PM (UTC)
Message
Greetings agian,I managed to finish up the plugin so hat it works the way it was designed to,and Im happy to say its public now.

http://rakonspage.topcities.com/resources.html

As always, feedback is greatly appreicated.
Thanks to Ked, and the Forums here for your help.

--Rakon

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[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.


30,953 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at HostDash]