|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Wed Feb 18, 2004 3:41 pm
[problem]counting character within a line |
I am try to make a trigger to count how many "a" in one line
as the screen show:
abisssaaaww weadnia waaa
there have 9 "a"
I used following method:
z=0
pattern:a
value:#math z @z+1
and use #sa @z to see the result,
but @z's value is 1,
how come?
how can I make it work?
thanks |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Wed Feb 18, 2004 4:42 pm |
if you set a trigger to just 'a' then your asking for trouble, but sence you did ask here you go:
#trigger {{a|A}(*)} {step2="";count=0
#var step1 %lower(%1%2)
#var step2 %replace(@step1," ","")
#loop %len(@step2),2 {#var step2 %insert("|",@step2,%i)}
#forall @step2 {#if %i=a {#add count 1}}
#echo %1%2
#echo there are @count a's}
probably going to have to wotk out the infinat trigger loop yourself. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Feb 18, 2004 5:18 pm |
I just had a Eureka moment on this problem.
Triggers only fire once per line, which is why the original trigger doesn't work. However, the fastest way to count a's is probably to remove them all from the string and compare the original length to the modified length. The difference should be the number of a's.
#TR {a} {#VAR step1 {%trim( %trigger)}
#VAR step2 {%replace( %lower( @step1), "a", "")}
#MATH z (%len( @step1) - %len( @step2))
#SAY @z} |
|
|
|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Thu Feb 19, 2004 12:05 pm |
oic~^^
I learn much from it,thx all
but there are another deeper problem,
how about if the string have color?
eg. there have 9 "a" but only 3 of them in red,
how can I make a trigger to count the right number of "a" in red? |
|
|
|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Fri Feb 20, 2004 7:30 am |
pls help me,
I really want to know the method. |
|
|
|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Sat Feb 21, 2004 2:09 am |
let me give a example for understand the situation
screen show:
ebacadfjianbasdasdefaaawaw
how can I make the trigger which only count out the number of red "a"? |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Sat Feb 21, 2004 2:39 am |
Change your triggers line color option to red
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Feb 21, 2004 3:04 am |
You might be able to do this with an ANSI-type trigger. I'm not interested in spending any time on it. I doubt anyone else is either, which is why you haven't gotten any answers. It's not that we don't understand what the problem is, it's that we don't see any point to it.
If you really care about the number of red a's, there are 3 of them in your example. I didn't need a trigger to find that out, I just used my eyes. |
|
|
|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Sun Feb 22, 2004 10:25 am |
the point to make the trigger possible is
that's the robot checker make by game master which stop my robot working effectively in game.
the problem I meet is the trigger only fire once on each line,
and there have color words.
if I just simply capture the line and analysis the string,
I can't find out the right number of red a.
if I use ansi trigger,
it only fire once on each line,
how can I counting it?
so,is there possible to make me against the robot checker?
I am a beginner of zmud,
I am really hopeful there have some senior user can teach me more about zmud.
thanks. |
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Tue Feb 24, 2004 8:33 pm |
A modification to LightBulb's solution.
You'll have to play with it yourself to modify it to match the colors actually used. This assumes low red and default changes to the ansi sequence.
#TR {a} {
#VAR step1 {%trim( %trigger)}
#VAR z 0
#WHILE (%len( @step1) > 0) {
#MATH Run %pos( "[31ma", @Step1)
#VAR RunEnd %pos( "[0m", @Step1)
#VAR z %eval( @z+%if( @Run>0, @RunEnd, 0)-%if( @Run>0, 5, 0)-@Run)
#VAR Step1 %copy( @Step1, %pos( "[0m", @Step1)+4, %len( @Step1))
}
#SAY @z} "" {color}
screen show:
ebacadfjianbasdasdefaaawaw
What I did to simulate your "screen show":
#SHOW a%ansi(red)a%ansi(default)alkjdflkajsdflkj%ansi(red)aaa%ansi(default)sdlkf%ansi(red)a%ansi(default)%ansi(red)a%ansi(Default)
So the trigger captures:
a[31ma[0malkjdflkajsdflkj[31maaa[0msdlkf[31maa[0m
Then it looks for runs of characters in red.
I leave it for you to develop the rest, the robot checker
will become harder and harder over time.
Edit to modify [ blue ] etc things |
|
|
|
szeming Newbie
Joined: 18 Feb 2004 Posts: 7 Location: Hong Kong
|
Posted: Sun Feb 29, 2004 11:50 am |
great!
thx a lot!
although I can't fully understand how it work now,
I will do my best to make myself clear.
learn much from it :P |
|
|
|
|
|