|
jaden198 Newbie
Joined: 25 Apr 2011 Posts: 3
|
Posted: Mon Apr 25, 2011 10:17 pm
Zmud Trigger in Cmud |
Original Zmud line was
#ALIAS target {targ=%1;zone=%2;#trigger {You see* <@targ>* to the (%w)} {ff %1 %%1} {@zone}}
Basically, the alias "target" could be used to designate targets within a given zone.
Target Squid Ocean
A class folder named Ocean would be created with a trigger that would initiate an attack on the mob Squid.
Sadly, this code doesn't move seamlessley into Cmud. Any help would be greatly appreciated.
Jason |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Mon Apr 25, 2011 11:02 pm |
You don't need <> to expand variables in CMUD anymore. Check out this page from the Changes for zMUD users section of the CMUD manual, it even has an example similar to what you're trying to do
|
|
|
|
jaden198 Newbie
Joined: 25 Apr 2011 Posts: 3
|
Posted: Tue Apr 26, 2011 4:36 am |
The idea is to manually build a list of targets contained in a particular zone. When I scan, I see:
You see the Clan Training Dummy to the west.
I'm attempting to create an alias that will create the trigger and class folder (if required) for the targets.
Right now, the alias, Target, looks like this:
$targ=%1
$zone=%2
#trigger {You see * @targ * to the (%w)} {smile} {@zone}
typing Targ Dummy Test results in the Test Class folder being created, and a trigger appearing within that folder...as it should. However, the trigger reads:
#trigger {You see * $targ * to the {%w} {smile}
for some reason, the $zone variable is being properly expanded to create the class folder Test, but the @targ variable is not being expanded to create a trigger including the word dummy.
Elaborate, if you'd be so kind :) |
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Tue Apr 26, 2011 12:36 pm |
nevermind -- misread the issue.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Apr 26, 2011 12:56 pm |
You haven't made clear what you want the trigger pattern to be. If you want the trigger pattern to be "You see * $targ * to the (%w)", then that is the correct way to do it (as you have seen). If, however, you want the trigger pattern to be "You see * Dummy * to the (%w)", you need to do something different. The #TRIGGER command will treat everything within that first set of braces as a literal string. To change that, you need to use #EXEC:
Code: |
$targ=%1
$zone=%2
#EXEC {#TRIGGER {You see * $targ * to the (%w)} {smile} {$zone}}
|
The #EXEC command will expand all variables within its argument before executing the argument as a command. Note that #EXEC should be avoided unless absolutely necessary, because it prevents the script from being compiled. It has to be compiled on-the-fly during execution, which will slow the script down slightly. This appears to be one of the few cases where it is necessary. |
|
|
|
jaden198 Newbie
Joined: 25 Apr 2011 Posts: 3
|
Posted: Tue Apr 26, 2011 2:02 pm |
#EXECUTE did the trick.
Alias: Target
$targ=%1
$zone=%2
#exec {#trigger {You see* $targ *to the (%w)} {ff $targ ~%1} ($zone)}
Creates a Class Folder for each zone and puts the trigger for each target within that folder. I can then scan to acquire targets and fire at them.
Thanks again. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Tue Apr 26, 2011 2:52 pm |
Hmmm... you would have to use %concat to atring together all the parts of a new trigger like that.... triggers really should not be created automatically anyhow.
Have you considered a database variable?
Code: |
#TR {You see {the |a |an |} (*) to the (%w).} {
$targ=%1
$direction=%2
#IF (!%ismember($targ, @mobs.%zonename)) {
#SAYADD { <send '#ADDITEM Mobs.%zonename $targ'>Add New Mob</send>}
} {
#SAYADD { <send 'ff $targ $direction'>Attack!</send>}
}
} |
This is untested, but it should detect weather or not a mob is in your to kill list, and add a clickable link to either add it to the kill list, or to initiate combat.
Edit: Well... looks like i was beat... thats what i get for going to bed with a post half answered. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Apr 26, 2011 4:08 pm |
Actually, Shalimar makes a good point. Depending on exactly what you are trying to do, it may be easier to do this as a stringlist or database variable. For instance, suppose @curzone is the name of your current zone, and @mobs is a database variable defined as in Shalimar's trigger. Shalimar's trigger is an interesting way to add new mobs to the list (I like that MXP code, Shalimar). Then all you need is the following trigger to fire the ff command:
Code: |
#trigger {You see* ({@mobs.@curzone}) *to the (%w)} {ff %1 %2} |
This way, you don't need a new separate trigger for each new mob. They are all listed in one database variable. This trigger can be left alone, and all changes are simple made in the variable @mobs. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Tue Apr 26, 2011 10:33 pm |
Rahab wrote: |
You haven't made clear what you want the trigger pattern to be. If you want the trigger pattern to be "You see * $targ * to the (%w)", then that is the correct way to do it (as you have seen). If, however, you want the trigger pattern to be "You see * Dummy * to the (%w)", you need to do something different. The #TRIGGER command will treat everything within that first set of braces as a literal string. To change that, you need to use #EXEC:
Code: |
$targ=%1
$zone=%2
#EXEC {#TRIGGER {You see * $targ * to the (%w)} {smile} {$zone}}
|
The #EXEC command will expand all variables within its argument before executing the argument as a command. Note that #EXEC should be avoided unless absolutely necessary, because it prevents the script from being compiled. It has to be compiled on-the-fly during execution, which will slow the script down slightly. This appears to be one of the few cases where it is necessary. |
Interesting. Any reason the #EXEC is required to expand local variables within the trigger pattern, but not the trigger code? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Apr 27, 2011 2:32 pm |
I think you are confused, Daern. Variables in both the first and second parameters of the #TRIGGER command (the trigger pattern and the trigger value, or trigger code) are _not_ expanded when executing the #TRIGGER command. They are expanded only when the trigger is fired, not when the trigger is created. The third parameter of #TRIGGER is different. The third parameter is the class in which the trigger itself should created when executing the #TRIGGER command. Clearly that has to be expanded when executing the #TRIGGER command, or else Cmud won't know where to create the new trigger.
In order to expand variables in either the pattern or the code when _creating_ the trigger, you need to use EXEC. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Thu Apr 28, 2011 1:07 am |
Rahab wrote: |
I think you are confused, Daern. Variables in both the first and second parameters of the #TRIGGER command (the trigger pattern and the trigger value, or trigger code) are _not_ expanded when executing the #TRIGGER command. They are expanded only when the trigger is fired, not when the trigger is created. The third parameter of #TRIGGER is different. The third parameter is the class in which the trigger itself should created when executing the #TRIGGER command. Clearly that has to be expanded when executing the #TRIGGER command, or else Cmud won't know where to create the new trigger.
In order to expand variables in either the pattern or the code when _creating_ the trigger, you need to use EXEC. |
No, I'm afraid you're wrong. You should actually test things like this before posting. You're correct that variables in the first parameter of the #TRIGGER command (the pattern) are not expanded, but they definitely are in the second parameter (the trigger code). I used this alias to test it:
Code: |
<alias name="maketrig" id="10044">
<value>$test = %1
#trigger {$test} {$test} {$test}</value>
</alias> |
Type maketrig testing on the command line. It made a new trigger, in the class testing, with code testing, but pattern $test. $test is also expanded perfectly while making aliases, functions and events. It also sorta worked with variables, though it wouldn't expand the local variable to be the name of the new variable, since it was just setting the existing local variable - this is expected. The only place that I couldn't make a local variable expand when creating a setting was in a trigger pattern. So, I repeat my question from my previous post:
Daern wrote: |
Interesting. Any reason the #EXEC is required to expand local variables within the trigger pattern, but not the trigger code? |
And after my more extensive tests today (yes, I tested that before posting the first time, too) I'll add on "Or any other setting, for that matter?" |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 28, 2011 12:50 pm |
Hm. I apologize. I didn't bother testing because it's not supposed to work that way and you didn't say that you had tested it. If it is acting the way your test seems to show, then I believe you have found a bug.
Try typing "#trigger {$test} {$test}" on the command line. It should make a trigger whose code is "$test"; in other words, it should be creating a local variable within the trigger. It _should_ act the same way when executing #TRIGGER from within a script. Otherwise, there is no way to create local variables within a trigger. I can't check this right now from work. Can you test it and post your results? |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Apr 28, 2011 4:42 pm |
No, local variables are *not* expanded within a trigger pattern, sorry. You would need to use #exec to do that.
When you put a variable in a trigger pattern, that variable is not expanded until the trigger is tested when each line is received from the MUD. If you want the variable expanded when the trigger is *created* then you need #exec.
If you don't want to use #EXEC, the other trick is to use %eval to force the expansion of the variable in the trigger pattern. When doing this you will also need to specify the optional first argument of #trigger which is the ID name. For example, this will work:
Code: |
<alias name="maketrig" id="10044">
<value>$test = %1
#trigger $test %eval($test) {$test}</value>
</alias> |
That will expand $test for the pattern. However, the $test within the script body of the trigger still won't be evaluated. To expand that in the trigger body then you still need #EXEC. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Thu Apr 28, 2011 8:07 pm |
Rahab, I had to modify that a bit, it wouldn't compile since it's trying to send the contents of the $test variable to the mud, and $test doesn't exist. #TRIGGER {$test} {$test = "testing";#show $test} worked fine, but $test = "testing";#TRIGGER {$test} {$test} created a trigger with the pattern $test and code testing. As I said before, the local variables are being expanded in the trigger's code, but not the pattern. So, there is a way to create local variables within a trigger - this problem only occurs if the local variable already exists when the trigger is being created.
Zugg, I'm aware that local variables aren't expanded within a trigger pattern, and I was asking why. Rahab explained it very well, and he also raises a very good point. As I just said, local variables _are_ expanded in the trigger code. If you want to make a trigger (or alias, etc.) with a local variable in it, and that local variable already exists, it will be expanded, and your trigger/alias/whatever won't work. Take this scenario, for example:
Code: |
<alias name="additem" id="10051">
<value>$temp = %1
#IF !%iskey(@itemdb,$temp) {
#ADDKEY itemdb $temp ""
#TEMP {^Name: (%w)%sLevel: (%d)} {$temp = %concat(%1," ",%2);#ADDKEY itemdb %dbkey(@itemdb,%numitems(@itemdb)) $temp}
#SEND %concat("identify ",$temp)
}</value>
</alias> |
Not the best code, I know, but I had trouble coming up with a scenario when something like this could actually happen This alias should add a key-value pair to a database variable, the key being the keyword of an item, and the value being the name and level of the item. The result is a key-value pair being added to the database variable, with the key being the keyword of the item, and the value also being the keyword. When I type additem helm, this trigger is created:
Code: |
<trigger priority="100530" temp="true" saved="false" id="10053">
<pattern>^Name: (%w)%sLevel: (%d)</pattern>
<value>$temp = %concat(%1," ",%2);#ADDKEY itemdb %dbkey(@itemdb,%numitems(@itemdb)) helm</value>
</trigger> |
As you can see, the local variable $temp is expanded when the temporary trigger is created, which is not at all what I wanted to happen. Obviously, situations like this won't occur very often, but nevertheless, I think there's good reason to make local variables not expand in the trigger code either, just like in the pattern, and if you do want them expanded in the trigger code you'll need to use #EXEC, just like in the pattern. The same thing should probably apply to other settings (as I mentioned in my previous post, local variables are also being expanded in aliases, functions, events and variables, at the very least).
Another solution, which I think would be better, is to make local variables always expand, even in trigger patterns, and if you wanted it to not expand, you would need to use #EXEC. For example, if you use this code:
Code: |
$test = "testing"
#TRIGGER {$test} {$test} |
it would make a trigger with the pattern testing, and the code testing, while if you actually wanted a local variable in the trigger you would do something like this:
Code: |
#EXEC "#TRIGGER {$test} {$test = "testing";#SHOW $test}" |
I think this second option would be more appreciated by CMUD users, since people probably want local variables to expand more often than not, and having to use #EXEC has always been really annoying, but I can't speak for everyone else.
This post ended up getting really long, sorry about that!
Daern |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Apr 29, 2011 1:59 am |
You're second option would not work, Daern. #EXEC is explicitly designed to expand variables. That is the main purpose of it. Your second solution would flip that on it's head, and break a lot of code as well.
|
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Apr 29, 2011 2:08 am |
Not if it's executing a string. I just ran this code on my command line:
Code: |
$test = "testing";#exec "#trigger {$test} {$test = "test123";#show $test}" |
$test was not expanded. It will be expanded if you do something like this though:
Code: |
$test = "testing";#exec {#trigger {$test} {$test = "test123";#show $test}} |
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|