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.
 Entire forum ➜ MUSHclient ➜ Python ➜ Trying to script a fairly simple trigger in python

Trying to script a fairly simple trigger in python

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


Posted by LupusFatalis   (154 posts)  Bio
Date Mon 22 May 2006 04:39 AM (UTC)
Message
... Well, I'm new to python, and what I'm trying to do is make a trigger on:

* You think your (some symbols) skill has improved. *

so in the trigger section I put:
^\* You think your * skill has improved\. \*$

and for send:
%0

Now, I wrote a little script in Python for it, or tried to...

def OnSkillGain(TriggerName, trig_line, wildcards):


VariableName += ''.join(['x' for x in wildcards])

VariableName = VariableName.replace(' ', '_').replace('\'', '').replace('-', '_').replace('#', '_')
VariableValue = world.GetVariable(VarName)

if not VariableValue:
world.SetVariable(VarName, 1)
else:
world.SetVariable(VarName, VariableValue+1)

Basically, what I'm trying to do, is read in the name of the skill, which in some cases can contain symbols I want to replace with other symbols... I get the following error.

Error number: -2147221005
Event: finding CLSID of scripting language "Python"
Description: Error -2147221005 occurred when finding CLSID of scripting language "Python":

Invalid class string

Called by:

Anyway, I'd appreciate any help. Thanks.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 22 May 2006 06:39 AM (UTC)
Message
See:

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

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #2 on Mon 22 May 2006 03:01 PM (UTC)
Message
Thank you very much. Everything is now working well after some tweaking, incase anyone wanted the trigger and corresponding script, here it is.

Trigger:
<triggers>
<trigger
enabled="y"
lines_to_match="2"
match="^\* You think your (.*) skill has improved\. \*$"
regexp="y"
script="OnSkillGain"
sequence="100"
>
</trigger>
</triggers>

Script, written in Python:

def OnSkillGain(TriggerName, trig_line, wildcards):

VariableName = ''.join([wildcards[x] for x in range(len(wildcards)-1)])

VariableName = VariableName.replace(' ', '_').replace('\'', '').replace('-', '_').replace('#', '_')

if not world.GetVariable(VariableName):
VariableValue = 1
else:
VariableValue = int(world.GetVariable(VariableName)) + 1

world.SetVariable(VariableName, str(VariableValue))
world.note(VariableName + ': ' + str(VariableValue))

Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #3 on Mon 22 May 2006 06:36 PM (UTC)
Message
Alright... Now, I finished the script that does all the skill handling on the mud. I want to convert it now to one coherant plugin. When I do this, the new variables that the scripts were creating as world variables are no longer world variables. I would like them to still be world variables. Or at the very least they don't show up as world variables. In fact, I wanted to see where they showed up, they aren't in the xml file either. Yet when I close the client and open it their values are stored. I don't know where. Now, if I can't keep them as world variables, thats fine, I could easily write a script to print them to the client when I want them. But I really would like to know where they are stored. I used the plugin wizard to create the plugin, it consists of two triggers and some scripts. I'll add to it later, but for now I just wanted to see how creating a plugin worked. As I am both new to Mushclient and Python... Though not new to programming. In any case, Thanks for your assistance.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 22 May 2006 09:06 PM (UTC)

Amended on Mon 22 May 2006 09:07 PM (UTC) by Nick Gammon

Message
Variables are private to each plugin, in case two plugin authors happen to use the same variable name (like "counter").

They are saved to a plugin "state" file which is in the State subdirectory, and is named by concatenating the world ID and the plugin ID.

For example, one of mine is named:


b55ac52c9b44ccc7f4f41562-982581e59ab42844527eec80-state.xml

World ID is: b55ac52c9b44ccc7f4f41562
Plugin ID is: 982581e59ab42844527eec80


The reason for using the World ID as well is to stop clashes with state files if you use the same plugin in multiple worlds.

You can easily view the current state file (which will be when it was last saved) by RH-double-clicking the name of the plugin in the plugins list in MUSHclient.

If you want to see the current plugin variables do this:


/world.Debug "plugins"


Alternatively write an alias that on demand will list the plugin variables and their contents.

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #5 on Tue 23 May 2006 02:11 AM (UTC)

Amended on Tue 23 May 2006 04:42 AM (UTC) by Nick Gammon

Message
... Alright, I'm down to the very last stage, got everything else working, everything works nicely as scripts triggers, and aliases. But when I tried to use the wizard and add them all, I get the following error...


Error number: -2147352567
Event:        Execution of line 147 column 40
Description:  unindent does not match any outer indentation level
Line in error: 
   if len(v) > 6 and v[:6] == 'skill_':
Called by:    Immediate execution

Line  102: Error parsing script (problem in this file)


...I haven't a clue why this is executing immediately, if that is, in fact, what is going on. The piece of my script it is looking at is right here... Which is something I modified from one of your examples:


def DisplayVariables(TriggerName, trig_line, wildcards):

	world.notecolour = 16
	variablelist = world.GetVariableList
	if (variablelist ):
  		for v in variablelist:
			if len(v) > 6 and v[:6] == 'skill_':
				world.tell(v[6:])
			else:
				world.tell(v)
			world.Note (' = ' + world.GetVariable(v))
	world.notecolour = 4


Thank you.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 23 May 2006 04:44 AM (UTC)
Message
I edited your post to add the code tag so we could see the indentation.

My Python skills are not very good, perhaps someone else can help here?

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #7 on Wed 24 May 2006 03:13 PM (UTC)
Message
Alright, thanks very much for your help, I got everything working fine as a plugin. You did a very nice job with this client. I did want to note one thing though. When I try to import everything from a script file, I get an error that the script tag is not in use or some such. And I can't figure out how to make it go away, even after I delete all the imported things. Now, this isn't much of a problem as I was just importing everything to make a modification to the plugin, then make it a plugin again. And as those were the only things I had in the world so far, I just made a new world. But I just thought it would be something you'd might want to change, or add support for importing files from plugins, etc... Anyway, thanks again. Now to contemplate what project I'm going to tackle next, heh!
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.


24,550 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.