|
Cbisazza Wanderer
Joined: 27 Feb 2003 Posts: 69 Location: Australia
|
Posted: Tue Nov 04, 2003 8:24 pm
counting items |
Any straightforward method of counting items on a line?
Having a line like:
In your pocket you see a piece of string, a blue tissue, a yellow tissue and a black cube.
Ideally I would like to have a string list and match it with the contents of a line, updating counters as it matches entries.
In order to do that, however, I would need a trigger that matches the same line multiple times, and while I have not tried it I'm pretty sure that will not work as expected.
----
Up to now the best thing I have come up with is modifying the interesting portion of the text so that it can be analysed with %countlist(), but this is pretty limited in most respects.
Ideas anyone?
Thanks, |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Nov 05, 2003 12:09 am |
%countlist is probably the most efficient method. See my post in the Finished Scripts forum.
As far as I know, triggers only do multiple matches on the same line for a small number of commands which are designed solely to modify the line before display, such as #SUB and #CW. |
|
|
|
hatespyware Apprentice
Joined: 16 Dec 2002 Posts: 103
|
Posted: Wed Nov 05, 2003 12:21 am |
I'd just count commas. I'm sure using some apriori info to come up with a solution that uses the language patterns would work.
|
|
|
|
Cbisazza Wanderer
Joined: 27 Feb 2003 Posts: 69 Location: Australia
|
Posted: Wed Nov 05, 2003 12:58 pm |
It's not as simple as counting commas. The easiest solution would involve changing the commas to pipes (|) and using %countlist(). But my problem is that this will count a lot of similar items as different ones.
To use the same example as above, lets say the items string was:
In your pocket you see a piece of string, a blue tissue, a yellow tissue and a black cube.
my 'items list' would be something like {tissue|string|cube}.
Now if I just use %countlist() on the modified string, I four items with a count of 1, but I would like it to ignore the fact that there are two tissues with different colours.
That's what I was referring to when I said that the solution was limited. It does work, but it's limited and at this time I can't think of a way of working my way around the limitations. Maybe I'll think of something :) |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Tue Nov 11, 2003 7:46 am |
The Fact is that they are seperate items
You wish to count them than that is what you get
However I did find a way to do what you want,
BUT it is tedious and has a flaw.
#CLASS {CountIt}
#VAR CountThem {}
#VAR CountThemA {}
#VAR CountThemB {}
#VAR CountThemC {}
#TRIGGER {^In your pocket you see (*).} {CountThem={%1};#var CountThemA %replace(%replace(@countThem,"blue",""),"yellow","");#var CountThemB %replace(%replace(@CountThemA,", ","|")," and ","|");#var CountThemC "";#forall @CountThemB {#addi CountThemC {%i}};#echo @CountThem;#echo @countThemA;#echo @countThemB;#echo @countThemC;#echo %numitems(@CountThemC)}
#CLASS 0
This is the long route, it could be condised, but i left it in to show you how I got the steps to work.
when you apply this to the above example you will see that it strips colors of items so that they become general, then it adds them to a new var witch auto matically takes out similar items.
The flaw is that color of items are gone
It is just an example
works good on the example. |
|
|
|
|
|
|
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
|
|