|
aslanthekat Novice
Joined: 17 Sep 2007 Posts: 44 Location: Missouri
|
Posted: Fri Jan 23, 2009 9:50 pm
Counting lines |
Hello,
I'm trying to write a trigger to count the number of lines until a blank line. Here is an example
My Prompt
You scan your surroundings...
South:
Mob1
Mob2
My Prompt
Obviously generic mob names, but I'd like to be able to start counting after South: and stop at the blank line before my prompt, and store the number of lines counted in a variable.
Thanks in advance |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Fri Jan 23, 2009 10:01 pm |
#TR {South:$} {#T+ lineCounter}
#TR "lineCounter" {*$} {#IF (%line=%null) {#T- lineCounter;#SAY counted @lineCount lines} {#ADD lineCount 1}}
Untested, but it should work |
|
_________________ Discord: Shalimarwildcat |
|
|
|
aslanthekat Novice
Joined: 17 Sep 2007 Posts: 44 Location: Missouri
|
Posted: Sat Jan 24, 2009 2:57 pm counting lines |
Thanks for the post
It didn't work for me, but I've figured out I'm going to have to do it a bit differently. I'm going to have to be able to store each line in a variable. This is sorta what i was thinking.
You scan your surroundings...
South:
Mob1
Mob2
Code: |
#TR {South:} {#until (%line=%null) {#Add mobs 1;#var %concat(mob,@mobs) %1}} |
I want it to do the #add mob thing until it sees a blank line. I'd rather not write a bunch of #cond statements, I just think its cleaner.
Thanks |
|
|
|
aslanthekat Novice
Joined: 17 Sep 2007 Posts: 44 Location: Missouri
|
Posted: Sun Jan 25, 2009 10:32 pm counting lines |
Ok, the one I posted above loops endlessly. It isn't stopping at a null line. If anyone has any suggestions I'd appreciate it.
Thanks again |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sun Jan 25, 2009 11:21 pm |
perhaps the line isnt null and has a space?
try checking for: %len(%line)<=3 |
|
_________________ Discord: Shalimarwildcat |
|
|
|
aslanthekat Novice
Joined: 17 Sep 2007 Posts: 44 Location: Missouri
|
Posted: Mon Jan 26, 2009 1:59 am |
I create an alias, testscan
Code: |
#var mobs 0
#show South:
#show Mob1.
#show Mob2
#show %null
#show Prompt |
If I do the following
Code: |
#TR {%1} {#if (%line=%null) {#sa stopped} {#Add mobs 1;#var %concat( mob, @mobs) {%1} } |
It counts and stores @mob1=South:, @mob2=Mob1, @mob3=Mob2, @mob4=Prompt and never executes #SA stopped
If I replace %1 with $ it doesn't count or store anything, but it does execute #SA stopped where it should. If I use *$ it creates the 4 variables, and executes #SA stopped. However, it creates 4 variables when it should only create two, and it doesn't fill them with anything. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Mon Jan 26, 2009 4:37 am |
change:
#TR {%1}
to
#TR {(*)}
using %1 in the pattern is not supported, %1 references whatever part of the pattern is surrounded by the first set of (parenthesis). |
|
_________________ Discord: Shalimarwildcat |
|
|
|
aslanthekat Novice
Joined: 17 Sep 2007 Posts: 44 Location: Missouri
|
Posted: Mon Jan 26, 2009 4:56 pm |
Using (*) I get the same result as I did using %1. It isn't stopping at the null line and it also counts the South: line
I added a condition
Code: |
#TRIGGER {South:} {}
#COND {(*)} {#if (%line=%null) {#sa stopped} {#Add mobs 1;#var %concat( mob, @mobs) {%1}}} |
This creates @mob1 and stores the correct value, but stops. It doesn't count the 2nd mob.
Now I'm back to
Code: |
#TRIGGER {(*)} {#if (%line=%null) {#sa stopped} {#Add mobs 1;#var %concat( mob, @mobs) {%1}}} |
which as I said counts everything except the blank lines when I execute my testscan alias.
Thanks again for your help
This is starting to irritate me. I know I'm missing something simple. It shouldn't be this hard. |
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: Mon Jan 26, 2009 8:12 pm |
I'm not sure why the blank lines aren't matched, but why don't you end the mob gathering when the prompt is found instead:
Code: |
#trigger Scan {^You scan your surroundings...$}
#cond Scan {^%w:$}
#cond Scan {(*)} {#if (%regex(%1,"^Prompt$")) {#state Scan 0} {#add mobs 1;#var %concat(mob, @mobs) {%1}}} {Loop Pattern|Param=100} |
The final cond statement will go in as a normal Pattern type instead of the Loop Pattern type, so you'll have to update the type of that trigger state to Loop Pattern manually. The value of 100 is just some arbitrarily large value higher than the number of mobs you will ever have. Effectively, this will add mobs to the list until the prompt is encountered. Not sure if its the best way to do it or not, but it seems to work. |
|
|
|
|
|