Then, if I want to follow something that's roaming about, I use /follow <name>, e.g. follow soldier.
This first argument (soldier in this case) is passed to the follow alias, then substituted for the %{*} variable.
The resulting expression is evaluated to generate a second definition, a trigger this time that takes the first parameterized value in the regular expression and sends that verbatim to the connected world; in this case it would be a direction in which to move.
The macro body above uses extra backslashes and dollar signs because of the number of times the expression gets passed over for evaluation; when you call /follow soldier, the macro body gets evaluated and becomes:
Does this make sense? The real key to take away here is that I define an alias that defines a trigger by substituting parameters for %{*}. You can also use another trigger to call this alias with a parameter to make it dynamic; just make a trigger that calls '/follow <param>'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So in your case, I'd try this:
/def updateLeader = /set leader %{*} %; /def -mregexp -t"^%{*} -- 'target (.+)'" leaderTarget = /set target %%P1
You'll still have the leader variable set, but it will also redefine your leaderTarget trigger everytime your leader changes. The %%P1 tells it to not substitute the first parameter when calling updateLeader, but strip one % off and evaluate the new subexpression. The %P1 then gets replaced with the first parenthetical expression in the regex.
You just call updateLeader when you change leaders.
Hopefully that helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That worked like a charm, thanks. What you said makes sense too; it's just a bit weird since I expected \ to escape the characters, not repeating the special character again (that IS what is happening right?)
Is there any reason why variable substitution isn't allowed in a trigger? Security related reasons (like injection?)
Also, if I want to use this leader variable for more triggers, can I just %; the end of updateLeader and add it on? I'm going to test it myself when I get the opportunity, but maybe you can give me an answer before I get to try it out.
Thanks again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've read the tf docs over and over, and I just can't figure out how to do this.
I've got a trigger
/def -mregexp -t"^%{leader} -- 'target (.+)'" leaderTarget = /set target %P1
but it doesn't work. I know this trigger works because I've manually substituted names for %{leader}, and the target variable gets set.
Can someone please help me out?
Oh yes, and I'm sure the leader variable is set, I checked with /set leader
I use something like this;
/def follow = /def -mregexp -t"^%{*} leaves ([a-z]*)\\\\.$$" dyn_follow_trig = /send %%P1
/def break_follow = /undef dyn_follow_trig
Then, if I want to follow something that's roaming about, I use /follow <name>, e.g. follow soldier.
This first argument (soldier in this case) is passed to the follow alias, then substituted for the %{*} variable.
The resulting expression is evaluated to generate a second definition, a trigger this time that takes the first parameterized value in the regular expression and sends that verbatim to the connected world; in this case it would be a direction in which to move.
The macro body above uses extra backslashes and dollar signs because of the number of times the expression gets passed over for evaluation; when you call /follow soldier, the macro body gets evaluated and becomes:
/def -mregexp -t"^soldier leaves ([a-z]*)\\.$" dyn_follow_trig = /send %%P1
Does this make sense? The real key to take away here is that I define an alias that defines a trigger by substituting parameters for %{*}. You can also use another trigger to call this alias with a parameter to make it dynamic; just make a trigger that calls '/follow <param>'
I made a mistake above in describing what the macro body becomes.
If I started with:
/def follow = /def -mregexp -t"^%{*} leaves ([a-z]*)\\\\.$$" dyn_follow_trig = /send %%P1
and issued "/follow Soldier", I'd get:
/def -mregexp -t"^Soldier leaves ([a-z]*)\\.$" dyn_follow_trig = /send %P1
(e.g. not %%P1 in the end, but %P1)
So in your case, I'd try this:
/def updateLeader = /set leader %{*} %; /def -mregexp -t"^%{*} -- 'target (.+)'" leaderTarget = /set target %%P1
You'll still have the leader variable set, but it will also redefine your leaderTarget trigger everytime your leader changes. The %%P1 tells it to not substitute the first parameter when calling updateLeader, but strip one % off and evaluate the new subexpression. The %P1 then gets replaced with the first parenthetical expression in the regex.
You just call updateLeader when you change leaders.
Hopefully that helps.
That worked like a charm, thanks. What you said makes sense too; it's just a bit weird since I expected \ to escape the characters, not repeating the special character again (that IS what is happening right?)
Is there any reason why variable substitution isn't allowed in a trigger? Security related reasons (like injection?)
Also, if I want to use this leader variable for more triggers, can I just %; the end of updateLeader and add it on? I'm going to test it myself when I get the opportunity, but maybe you can give me an answer before I get to try it out.
Thanks again!
how can i check if a variable is set in an if block? This doesn't work
if (%{first}) \
this neither
if (first) \