|
Gurlok Beginner
Joined: 15 Dec 2012 Posts: 11
|
Posted: Sat Dec 15, 2012 5:29 am
Count the number of monsters? |
Hi Everyone
I was hoping to get some help on creating a trigger that could identify the number of monsters in a room and then if greater than a certain value, set a variable to true? This would of course change on every room movement. Essentially, if the room has more than 6 monsters I know I want to stop and further inspect it. My hope is that I could walk through an area and have Cmud count the monsters rather than me. This is the tricky part...
The room will be displayed as:
Snowy Plains: A Long Barren Trail [n]
Two rabbits, a small snake and four wolves are here.
or
Snow Plains: A Long Barren Trail [se]
A traveller is here.
The names are limited, I have a list of them already and can provide if it is needed. The number that could potentially preceed them is also limited, it is "two" through "six".
I don't even know where to begin with this. My Cmud kung-foo is weak. Is this even possible?
Thanks |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4702 Location: Pensacola, FL, USA
|
Posted: Sat Dec 15, 2012 7:41 am |
Code: |
#TR {(*) {is|are} here.} {
#LOCAL $mobCount
$mobs=%replace(%replace(%1, ", ", "|"), " and ", "|")
#FORALL $mobs {
#SWITCH (%word(%i, 1))
(two) {$mobCount=($mobcount+2)}
(three) {$mobCount=($mobcount+3)}
(four) {$mobCount=($mobcount+4)}
(five) {$mobCount=($mobcount+5)}
(six) {$mobCount=($mobcount+6)}
{$mobCount=($mobcount+1)}
}
#IF ($mobCount>5) {#SAY stop}
} |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Gurlok Beginner
Joined: 15 Dec 2012 Posts: 11
|
Posted: Sun Dec 16, 2012 4:44 am |
Shalimar thank you!
Cmud is reporting a parse error when I paste the above into the terminal. "Error parsing command: command list expected"
Let me see if I understand some of the logic behind this so I can attempt to correct it.
The first line is the pattern match. It will match on anything that is in the room via the * wildcard and the is|are here.
Line 2 creates a local variable called "mobCount" (only valid within this triggers "life". do not predefine this as it is created and destroyed on the fly)
Line 3 appears to replace the contents of the stringlist local variable "mobs" with the names captured via line one? (I do not see where $mob is created however? As a local variable does it not need to be preceeded by #LOCAL to set it?)
Line 4 is saying for every entry in the $mobs string list....
Line 5 Change the "word" found in the $mob stringlist with the value of 1?
Line 6-11 are basically "add-ons" like an IF statement saying IF "two" appears then add +2 not +1 to "mobCount", the same for three, four, five and six.
Line 12 closes off the switch statement
Line 13 sends the word "stop" to the screen (not the mud) if $mobCount is greater than 5
So the theory is, I could walk and this will gather the monsters in the room into the string list, replace their names with values of 1, if "two", "three" etc preceeds any of their names then their value is incremented by that amount, once the value reaches over 5 it sends the screen a display message.
Other than not seeing where $mobs is being created/declared it pretty much makes sense...unless everything I wrote above is totally wrong! I will mess with it some tonight to see if I can get it to work and will report back if I am successful. Please let me know if there is something minor that is hanging this up or if I left out a component needed to make it work.
Thanks! |
|
Last edited by Gurlok on Sun Dec 16, 2012 5:10 am; edited 1 time in total |
|
|
|
Gurlok Beginner
Joined: 15 Dec 2012 Posts: 11
|
Posted: Sun Dec 16, 2012 5:09 am |
After reading the help menu again I see the example for #SWITCH
#SWITCH (@a=1) {a is one}
(@a < 0) {a is negative}
(@a=10) {a is ten}
(@a >= 10) {a is ge ten}
{nothing matched}
I don't see the first command in the provided trigger after (%word (%i, 1)). Should there be something there or does the trailing {$mobCount=($mobcount+1)} cover it since it is not preceeded by an expression? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Dec 16, 2012 5:20 pm |
Your problem is that the code example doesn't have the closing } for the #TRIGGER's executed code.
To answer your question, though, #SWITCH has 3 basic formats:
1)single-line format
Code: |
#switch (condition1) {code1} (condition2) {code2} (conditionN) {codeN} |
2)multiline format with differing conditions
Code: |
#switch (condition1) {code1}
(condition2) {code2}
(conditionN) {codeN} |
3)multiline format with multiple results for same condition
Code: |
#switch (condition)
(result1) {code1}
(result2) {code2}
(resultN) {codeN}
{else code (no condition supplied)} |
Multiline format absolutely must be properly indented or you will get a syntax error. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Gurlok Beginner
Joined: 15 Dec 2012 Posts: 11
|
Posted: Sun Dec 16, 2012 5:59 pm |
MattLofton,
Thanks. I moved the final } up a line to be directly behind
#IF ($mobCount>5) {#SAY stop} so that it now looks like this
#IF ($mobCount>5) {#SAY stop}}
That allowed the trigger to save, however now when I walk around I am seeing this:
ERROR: Trigger "(*) {is|are} here." fired but did not compile
There appears to be matching { and } the whole way through (I tossed it into notepad++ to double check). |
|
|
|
Gurlok Beginner
Joined: 15 Dec 2012 Posts: 11
|
Posted: Sun Dec 16, 2012 6:06 pm |
Shalimar and MattLofton,
Thank you! I got it working. Part of the problem appears to have been the lines in the #SWITCH command were wrapping and were not on their own lines, indented from the first line, something I found as a requirement for #SWITCH in the help menu. Once I put the code into notepad++ I could see that they were wrapped and not newlines. I guess that was lost in the copy/paste between the forum and my settings/notepad. |
|
|
|
|
|