|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 10:13 am
removing parts of a string list help |
here is what I want to do
read a some text in from the mud and store it into a string list
take that string list and remove words based on another string list
ie
mud text: The big bad wolf
so var1 = The big bad wolf (no prob on this part)
I convert it to a string list string1 {The|big|bad|wolf} (again no prob)
and I have say string2 {The|big|bad}
the prob is removing items in string2 from string1
Ive tried various forms of %replace and %remove to no avail
any suggestions? |
|
|
|
iljhar GURU
Joined: 10 Oct 2000 Posts: 1116 Location: USA
|
Posted: Sat Dec 15, 2001 10:38 am |
Try this:
#forall @string1 {#if (%ismember(%i, @string2)) {#delitem string1 %i}}
Iljhar |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Dec 15, 2001 10:50 am |
Minor correction:
#forall @string2 {#delitem string1 %item(@string2,%i)}
If you try the other way it will miss words. Because %i=1, you delete the first item, then %i becomes 2 but what used to be the second item is now the first. |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 11:36 am |
nope didnt do it
here is what I got so far that works
here is an example mud line:
a big bad wolf appears
I have the following trigger to grab the line
#trigger &mobget appears {
#var string1 %replace( "%1", " ", "|")
#var string2 {a|big|bad}}
what I want to do is eventually end up with
string1 = wolf |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Dec 15, 2001 1:39 pm |
What version are you using?
Kjata |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 2:37 pm |
6.23 beta
|
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 3:23 pm |
let me see if I cant explain it in another way
I want to take stringlist a compare it to stringlist b and remove from stringlist a any occurance of string b
so if:
string a {A|big|bad|wolf}
string b {A|big|bad}
after comparing
I want string a {wolf} |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Dec 15, 2001 4:11 pm |
What has been posted so far is correct. The problem appears to be that the functions and commands to do what you want have bugs in 6.23 and do not work as they should.
Kjata |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 4:22 pm |
figures I'd find a bug
thought it was just my rusty coding that was the problem or
maybe a typo or 2 on my part
I'm gonna see if I can't work around this and if I do I'll post the code |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 4:46 pm |
ok I found the problem after trying just about every which way in the book and it is
pretty simple
try this out
list="sword|ring|shield";#FORALL @list {#echo %i}
zmud returns
sword
ring
shield
ok no prob seems to work
it appears that the #forall command ONLY looks for @list as the name of the stringlist
any other name will cause it to just display %1 for each of the elements of stringlist
so in other words
testlest="one|two|three"
#forall @testlist {#echo %1}
zmud returns
%1
%1
%1
and since I dont have access to the beta forum I am wandering if
some kind hearted soul can pass this on over to the beta forum
and I haven't found a work around for it yet Im going to try
straight string manipulation instead of a stringlist and see what I can come
up with but if it gets to long I'll just wait til they change/fix #forall
and use an alias to reset the @list stringlist for the timebeing til
I come up with something else |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 5:18 pm |
ok I figured it out arhg what a pain in the a$$
ok here it is and yes it works
#FORALL @list {#IF (%ismember( %i, @somestring)) {#DELITEM somestring %i}}
just wish I didnt have to feed @list with info from another stringlist but
like I said it works |
|
|
|
Acaila Apprentice
Joined: 30 Aug 2001 Posts: 187 Location: Netherlands
|
Posted: Sat Dec 15, 2001 7:02 pm |
quote: testlest="one|two|three"
#forall @testlist {#echo %1}
zmud returns
%1
%1
%1
There's a reason it's acting that way, and it's because you made typos in your script, not because it's bugged.
1) You made a variable called Testlest and call it later using Testlist. zMUD can't find the variable you're refering to, and thus can't parse the %1.
2) You need to use %i in a loop structure to diplay the current item. Using %1 always displays the first item no matter what the current one is.
Acaila |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 7:23 pm |
I know I made a typo but try it out :)
testlist="one|two|three"
#forall @testlist {#echo %1}
try it and see what happens
but if you do something like
testlist="one|two|three"
list @testlist
#forall @list {#echo %1}
it will work
basically all I'm saying is yes I have it working
but for #forall to work it HAS to have @list as the list
no ifs ands or buts
test it and you will see
both examples
1st one doesnt
2nd one does |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Dec 15, 2001 8:09 pm |
quote:
testlist="one|two|three"
list @testlist
#forall @list {#echo %1}
it will work
this is what was being referred to. Instead of using %1 there, use %i, which will correspond to the correct item in the @list variable used by #FORALL
li'l shmoe of Dragon's Gate MUD |
|
|
|
dysonsphere Beginner
Joined: 11 Dec 2001 Posts: 16 Location: Canada
|
Posted: Sat Dec 15, 2001 9:03 pm |
DOH!!!!!
man I need more sleep for not catching that one
sheesh
beg ya pardon that'll teach me to stare at computer screens 18 hrs a day
man I feel stupid atm |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Dec 15, 2001 9:23 pm |
Hrm, my bad. I didn't realize FORALL puts the item in %i. Figured it just ran a numeric counter like the rest of the looping commands. Guess that is what happens when you don't read the help. Anyhow, I am glad you figured it out.
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Dec 17, 2001 5:16 pm |
Wouldn't it be simpler to skip the #IF and just do the deletes?
#FORALL @string2 {#DELITEM string1 %i}
LightBulb |
|
|
|
|
|