|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Oct 12, 2007 9:41 pm
Using functions in triggers |
In another post we were talking about using %concat in a function. What I learned about functions within trigger patterns is that they seem to work if the %function name doesn't look like a wildcard. For example,
%word(...)
looks like a %w wildcard to the trigger pattern parser.
This means that %concat *should* be working. Here is what I just tried in 2.06:
Code: |
Name=Zugg
#TRIG {Test%concat(@Name,"s")} {#SHOW fired}
#SHOW TestZuggs -> fired
Name=Chiara
#SHOW TestZuggs -> didnt fire
#SHOW TestChiaras -> DID fire |
So this example seemed to work just fine.
Now, as far as handling functions that start with the same letter as a wildcard, what do people think of using the %%function syntax to embed a function within a trigger pattern? I think it might be pretty easy to implement. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Oct 12, 2007 9:50 pm |
Oh yeah, in v2.05 you need to enter each line above separately. When a variable was changed in v2.05, Triggers were only updated by a message sent to the main thread, so changing "Name=Chiara" didn't effect the trigger until the entire script was done. So if you enter all the lines as a single command line script, it would fail, but entering each line itself would work. In v2.06 this isn't a problem since triggers are properly expired even in background threads (only buttons and status bar items wait for the main thread)
|
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Fri Oct 12, 2007 11:42 pm |
%%function seems fine to me. I think it's important that this syntax would also work for functions that don't start with the same letter as a wildcard though - for consistency.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Oct 13, 2007 12:32 am |
I am not sure how exactly you are handling it with the regex engine, but I think I would rather prefer %{name of whatever} since this is already a valid syntax. Some examples being %{i} @{%{i}Variable}
I think %{concat("word1","345)} would be better then the doubled percent. Currently 2.05 gives an error on parsing that when it is done with a #SHOW from the command line. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Oct 13, 2007 4:18 am |
Actually, it was a lot easier to handle the %% in the parser than to use %{}. Although I'll also try to support that syntax in the future since the fact that it's not already working seems to be a bug.
And yes, it works for any function, regardless of whether they start with the same letter as a wildcard. Let me know how they work in 2.06 (yes, this post probably should be in the Beta forum, sorry) |
|
|
|
|
|