Trigger/Variable Capture Problems

Posted by Xerakon on Fri 11 Apr 2014 01:08 AM — 10 posts, 38,787 views.

USA #0
Hello everyone!

Just recently have begun converting over from CMUD to MUSH! But I am having a ton of problems trying to get things going here. Although I have scoured the forums, perhaps I need abit more babying.


You have 780 (780) hit points and 1623 (1623) social points.


Is what I'm trying to convert to variables so I can put in health bars and such. These values should be the variables of hp, maxhp, sp, and maxsp.

Now, in the trigger editor, I have:


^You have (.*) ((.*)) hit points and (.*) ((.*)) social points.


Send box contains: %1

Send to: Variable
Variable: hp

But it sends nothing to the variable. any ideas why or what I need to do to get it to start capturing?

Thanks!
USA #1
You want to change the regex a bit as it's not capturing I imagine due to the parenthesis not being escaped with \ use.

^You have (.*?) \((.*?)\) hit points and (.*?) \((.*?)\) social points\.$

OR if you want the regex more specific to numbers

^You have (\d+) \((\d+)\) hit points and (\d+) \((\d+)\) social points\.$

Try one of those.
Australia Forum Administrator #2
BlackGuard is right about the parentheses.

Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.
USA #3
Okay. I've fixed the trigger capture portion. However, the variable is still not filling. I'm thinking that I am incorrectly filling out the wizard.

See the below image.

http://i108.photobucket.com/albums/n24/Xerakon/SWMud/triggerprob_zps6ca77509.png
Amended on Fri 11 Apr 2014 04:45 PM by Xerakon
USA #4
Hrm... That's not typically how I edit variables. But with your method, you have to make sure the variable is already created first.

Go to the variable tab and make sure that 'hp' is already added then the trigger should work.

How I normally do variables is through a script file. In that instance, I'd just set the trigger to send to script and in the send box put:

hp = "%1"
mp = "%2"
sp = "%3"
etc all in one trigger. But that sort of set up might be a touch complicated since it deals with a file outside of MUSHclient, I think.
USA #5
You also want to check off the box that the trigger is a regular expression.
USA #6
Here's what it's currently looking like. Still not filling in the variables. And the variables are already created.

Trigger line:
^You have (\d+) \((\d+)\) hit points and (\d+) \((\d+)\) social points\.$


Send box:
hp = "%1"
maxhp = "%2"
sp = "%3"
maxsp = "%4"


send to: Script

Enabled is checked.
Regular Expression is checked.
USA #7
Oh, the variables are there but there in a different section entirely if you're using my method.

MUSHclient variables are located in the variable table and are referenced with stuff like this in triggers:

SetVariable ("hp", "%1")
SetVariable ("mhp", "%2")
SetVariable ("sp", "%3")
SetVariable ("msp", "%4")

So you'd use the above. The example I listed earlier with stuff like:

hp = "%1"
mhp = "%2"

etc That would only go in the trigger if you were referencing variables in the matrix (I think that's the term) created OUTSIDE of MUSHclient. Like if you wanted, you could open notepad and write your entire system in there with variables and functions. And then use MUSHclient to manipulate the information in this manner. But that can be overly complicated and confusing. So just use the SetVariable stuff for now.
USA #8
Okay, got it to work using your coding there! Awesome, thanks so much!

In CMUD, there were short-cuts. is there anything like that in MUSH pertaining to triggers/variables?

For example, this trigger:

You have &hp ~(&maxhp~) hit points and &sp ~(&maxsp~) social points.


This would have automatically created the variables and filled them with values.
Amended on Fri 11 Apr 2014 10:15 PM by Xerakon
Australia Forum Administrator #9
No, nothing like that which automatically fills variables.

I'm a little opposed to things that "automagically" do things for you. I somewhat prefer a procedural approach where you can see what is happening.