|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Mon Aug 06, 2007 12:58 pm
code question |
How can i get my #if/%if statements to do more then one thing?
like, if a mob flees i want to Walk after it And attack it again.
Also, how do i make a button to toggle it off when the button is pressed down and on when it is not pressed down. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Mon Aug 06, 2007 1:15 pm |
Code: |
#IF (@myvar == "whatever") {
chase mob
attack mob
} |
or (assuming standard special characters)
Code: |
#IF (@myvar == "whatever") {chase mob;attack mob} |
There's a button type called "toggle." Try that and see how it works for you? |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Mon Aug 06, 2007 1:24 pm |
These are very generic questions so I will give a generic answer.
To get an #if to do more than one thing you do this.
#if (@variable=1) {west;jab @target} {Jab @target}
The semi-colon tells Zmud/Cmud to do another command.
If you want to toggle off something with a button you can do it two ways.
#if (@buttonDown=1) {#say The button is down} {#say The button is up}
And you place the buttonDown variable in the Variable stop in the button preferences.
%if is fairly similar to #IF except that it does not execute commands. It returns a string.
#say %if(@variable=1,"I will return this","I will return that")
If you actually want something to happen you will have to call those Ifs. Usually using a trigger.
Let's say that the mud gives you the following text.
The jackrabbit you were fighting has just escaped to the west.
You would need a trigger.
#trigger "autochase" {^The (%w) you were fighting has just escaped to the (%w).$} {#if (@buttonDown=1) {#exec {%2};stab %1} {#say I'm not going to follow him.}}
The %w means match any word. The () around it means capture the word that you matched. The first () captures to %1 the second to %2 and so on.
The ^ means start matching at the beginning of a line. The $ means this is the end of the line.
The second way to use the button is to use a #T- autochase to turn off the trigger. and #T+ to turn on the trigger.
Edit: I took far to long to post this and Larkin beat me. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Mon Aug 06, 2007 2:12 pm |
Larkin: Thanks for a good answer, and a very fast one.
Arminas: That was a greate answer, from my question you evaluated my skill (or lack of) and gave a comprehesive answer that will also answer many future questions.
I love this comunity. |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Mon Aug 06, 2007 4:18 pm |
Ok. Followup question:
The normal string to fire the trigger is like this :@target has fled!$@target (%w) (%w).
But sometimes, when the target is a sneaking race only the first line comes up.
So my question is, is there a way to get:
"The drow scout has fled!"
to fire on one trigger and
"The drow scout has fled!
The drow scout crawls east."
To fire another trigger withouth fireing the first? |
|
Last edited by dolgan on Mon Aug 06, 2007 6:27 pm; edited 2 times in total |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Mon Aug 06, 2007 5:53 pm |
If the mob has fled but the direction that the mob has fled is not given there isn't much you can do unless you have some command that can find where it went.
In this case, and with the lack of experience you have with scripting I would suggest that you don't make another trigger for this at all.
I know that isn't what you wanted to hear. Perhaps someone else will be able to help with more information. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Mon Aug 06, 2007 5:59 pm |
There is a command, thats why i want it to fire another trigger.
I want to make two different triggers, but the problem is that the first line is the same.
The drow scout has fled!
The drow scout crawls east. <- fires trigger 1
The drow scout has fled! <- fires trigger 2 but not trigger 1
And im learning at an amazing rate here. ;) |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Tue Aug 07, 2007 11:38 am |
You can make one trigger for the "so-and-so has fled" line and another trigger for the "so-and-so crawls that way" line, giving the second trigger a named ID that you can use to control it. When the "fled" trigger fires, you track the name of the critter (if needed) and enable the "crawls away" trigger. On the prompt (or whenever is appropriate) you do your processing of the stuff you captured and turn off the "crawls away" trigger (again, if needed). If you saw something flee and didn't see which way, you do your "find it" ability then.
|
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Tue Aug 07, 2007 1:00 pm |
A break down of what Larkin means.
You have your first trigger.
@target has fled!$
In the script you turn on two triggers.
#If (blah blah) {#T+ FledDir;#T+ FledPrompt} {I'm not set up to auto follow}
Then you have your two other triggers.
#trigger "FledDir" {@target (%w) (%w).} {#If (blah blah) {go direction and attack} {I'm not set up to auto follow};#T- fledDir;#T- FledPrompt}
#trigger "FledPrompt" {however you match the prompt in your mud} {send the find direction command;Turn on the find direction trigger} {I'm not set up to auto follow};#T- fledDir;#T- FledPrompt}}
And finally the find direction command trigger.
#trigger "findDir" {^He went (%w).$} {#If (blah blah) {go direction and attack} {I'm not set up to auto follow};#T- findDir}
Again, this is rather generic but it should help.
I used an if in all of the triggers so that at any time you could turn it off with your button. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Tue Aug 07, 2007 3:11 pm |
Thats just awsome, and i learn a few new commands everytime i ask somthing.
Thanks a bunch for the excelent help. |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Thu Aug 09, 2007 4:28 pm |
Ok, im having some problem with this trigger pattern.
@target has fled!${someone|@target} (%w) (%w).
its the {someone|@target} that seems to be the fault.
I want it to fire on either "someone" or the name stored in the variable @target.
How do i type that correct?
example of mud output.
Thief has fled!
Thief walks west |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Aug 09, 2007 5:13 pm |
This appears to be a bug.
The $ is being construed by the compiler to be the beginning of a local variable. Because the local variable $someone can never be declared, and indeed is not supposed to be, the compiler is throwing an error.
I do not know if this bug has already been fixed in the new version but I figure I can just wait until I play with it and see at this late date!
Anyway to make this work as expected you can turn the pattern into a regular expression and it works.
@target has fled!\n(?:someone|@target) (\w+) (\w+)\.
In the trigger options just check regular expression and use the above pattern. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
dolgan Beginner
Joined: 15 Jul 2002 Posts: 13
|
Posted: Thu Aug 09, 2007 6:02 pm |
Ahh.. so i actualy did it right then. yay..
Thanks, ill give it a try. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Aug 09, 2007 7:56 pm |
You could just escape the $ character by putting a ~ before it and it'll be ignored by the parser.
@target has fled!~${someone|@target} (%w) (%w).
Is working fine for me. Also, in the future you can sometimes see what kind of error is being thrown on the Compiled Pattern tab, if the pattern's failing to compile. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Aug 09, 2007 8:11 pm |
Did you actually get the trigger to fire Fang?
I tried escaping the $ as you did before I converted the pattern to regex and it did not work for me.
I also tried again right before posting this. Again Nada... |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Aug 09, 2007 8:23 pm |
I didn't actually try firing the trigger, which might be the problem - adding the tilde got the pattern to compile and I assumed that it'd start working after that.
You're right, there definitely seems to be a bug here. Even this simple example didn't work despite the pattern compiling.
#trig {test~$test} {#say fired}
#2 #say {test}
Then again, this entire problem can be avoided by using $ at the end of the pattern and using a multistate trigger instead. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Thu Aug 09, 2007 8:55 pm |
Honestly, I always thought that using $ for a linebreak in the middle of a pattern was simply bad style and not intended to work that way. I would actually recommend you use a multi-state trigger or a regex with \n, as was suggested.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Aug 09, 2007 9:21 pm |
I'm with Larkin on this one.
What escaping the $ does is check for the actual dollar sign. It's certainly not meant for multi-line matching, just end of lines. |
|
_________________ Asati di tempari! |
|
|
|
|
|