|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Wed Mar 30, 2011 5:37 am
Access class/variable from within an expression trigger? [3.33a Pro] (Solved) |
I have a class named "stats." I have a trigger:
Code: |
#TR {(@stats/var1 - @stats/var2)} {do some stuff.}
|
After I save this trigger and look at it in the package editor, I can see that Cmud is reading my class reference as a division symbol. (or at least, that's what i observe to the best of my ability) The @stats is underlined and blue, as if @stats is a variable by itself. It does not recognize var1 or var2, but both "@stats" are blue and underlined. How can I get this parsed the way i want it? What i want to do is subtract var2 from var1. They are both in the same class, but not in the same class as this trigger i'm having issues with.
Thanks again for any help and time offered.
Grunthork[/code] |
|
Last edited by grunthork on Thu Mar 31, 2011 11:38 pm; edited 2 times in total |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Mar 30, 2011 1:40 pm |
Right now, your code looks for a variable named @stats (let us assume that @stats contains the word "something"), and then triggers on text that looks like:
"something/var1 - something/var2"
and it puts that string into %1.
Can you explain exactly what you do want to do? Explain what @stats is, exactly where your variables are, and what string this is supposed to match. |
|
|
|
Myrkul Wanderer
Joined: 21 Aug 2008 Posts: 85
|
Posted: Wed Mar 30, 2011 1:47 pm |
[edit][/edit]
|
|
Last edited by Myrkul on Thu Apr 14, 2011 10:53 pm; edited 1 time in total |
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 31, 2011 1:18 am clarification |
My apologies. for not being clear. I'm performing a math operation here. I want to subtract stats/var2 from stats/var1. Another way to write this is var1-var2. The variables are members of a class in my package called stats, so i'm referencing the variables by typing them as classname/varname, which works in the script of the trigger, but not in the pattern. I'm subtracting two variables, and comparing their difference to a constant number:
Code: |
#TR {(var1-var2) < 500} {do something}
|
or
Code: |
#TR {(classname/varname1 - classname/varname2) < 500} {do something}
|
Hopefully that makes sense. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Mar 31, 2011 1:22 am |
@//module/class/.../varname.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 31, 2011 1:31 am |
I don't quite understand. What's the module? this trigger is in my "auto" class, and the variable is in the "stats" class. Both classes are under the root of the same window. But when I try to reference the variables in the "stats" class by using "stats/var1" it doesn't recognize the variable.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Mar 31, 2011 12:25 pm |
The module in Matt's example would be the name of the window. So, you could reference the variable as
@//windowname/stats/var1
Or you don't have to specify the window name:
@/stats/var1
When you use @stats/var1 it will interpret @stats as a variable itself. Are you certain you even need to specify the class? If you don't have any other var1 elsewhere, you can just do @var1. This is a good reason to use unique and descriptive variable names.
In addition, you cannot normally perform mathematics within a trigger pattern. Putting things within parentheses in a trigger pattern means something completely different from using it in a Cmud command. In a trigger pattern, it means "store whatever is captured by this sequence in a temporary variable", the variables being automatically named %1, %2, etc. That's why Myrkul suggested using %%eval, which is a way to force a function to be called within a trigger pattern. In this case, it would execute %eval() on the string and perform the subtraction and would match any string matching the resulting number.
However, now it looks like you actually are trying to do an expression trigger, which is completely different. Parentheses do work in expression triggers the way you expected. The trigger you have posted is a normal string-matching pattern. You have not specified that it should be an expression trigger. The trigger you want should be something like this:
Code: |
#TR {(@/stats/var1 - @/stats/var2) < 500} {do some stuff.} "auto" "Expression" |
I don't remember for sure if this is the correct syntax for specifying the trigger type, and can't check from here from work. Could someone else verify the above for me? |
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 31, 2011 10:03 pm |
Alright it seems I didn't use the right terminology. I am using an expression trigger, and I have exactly what's in rahab's code section above. It doesn't work, however. I'm using the package editor, and i can see that even with an expression trigger, cmud does not recognize the above code in parentheses as a variable. the entire @/stats/var1 isn't recognized as a variable. None of it is. Using the module when referencing the variable produces the same results. Does this mean i just can't reference a variable from within another class in an expression trigger?
thanks again for everyone's time and effort. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Mar 31, 2011 10:34 pm |
Aren't () and {} mutually exclusive in expression-trigger patterns?
ie, this is wrong:
#trigger {expression}
and this is right:
#trigger (expression) |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 31, 2011 11:13 pm Possibly |
They may be true, but i'm not using the command line. I'm using the package editor.
|
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 31, 2011 11:38 pm |
Thanks Rahab. It looks like you were right. What confused me was that the variable name wasn't getting highlighted in blue. All my others did, so I expected this one to as well. The expression does not highlight the class variables at all, but this trigger does fire, and works as intented! Thank you all!
|
|
|
|
|
|