|
hav Wanderer
Joined: 05 Oct 2004 Posts: 61 Location: Riga, Latvia
|
Posted: Fri Mar 25, 2005 1:03 am
problem with #forall |
I need to remove all items that isnt golem from stringlist.
golems are defined as
#var golemliste {rope golem|straw golem|clay golem|wood golem|stone golem|flesh golem|iron golem|crystal golem|diamond golem}
and lets say stringlist is
#VAR liste2 {stone golem|phase spider}
I tried
#FORALL @liste2 {#IF (!%ismember( "%i", @golemliste )) {#DELITEM liste2 "%i"}
quick test returns
#FORALL @liste2 {#IF (%ismember( "%i", @golemliste )) {#ECHO ismember %i} {#ECHO !ismember %i}}
!ismember stone golem
!ismember phase spider
What am I doing wrong, tried %i, "%i", {%i}, but "stone golem" instead of %i works,
#FORALL @liste2 {#IF (%ismember( "stone golem", @golemliste )) {#ECHO ismember %i} {#ECHO !ismember %i}}
returns
ismember stone golem
ismember phase spider
Alternative method to clear @liste2 would also be acceptable. |
|
|
|
Maelstrom Apprentice
Joined: 10 Feb 2005 Posts: 158
|
Posted: Fri Mar 25, 2005 2:23 am |
This should work... at least it did on my machine
#FORALL @liste2 {#IF (%ismember("%i",@golemliste)) {#DELITEM liste2 "%i"}} |
|
|
|
hav Wanderer
Joined: 05 Oct 2004 Posts: 61 Location: Riga, Latvia
|
Posted: Fri Mar 25, 2005 2:39 am |
grin, you're doing the opposite. the idea is to delitem anything that is not golem.
regardless of that though, one item on liste2 is golem and the other is not, so said loop should remove one item as opposed to both or none. doesnt work like that for me. |
|
|
|
DeReP Adept
Joined: 14 Jun 2003 Posts: 222 Location: Chile
|
Posted: Fri Mar 25, 2005 3:35 am |
tryed it with a ! sign?
#FORALL @liste2 {#IF (!%ismember("%i",@golemliste)) {#DELITEM liste2 "%i"}} |
|
|
|
hav Wanderer
Joined: 05 Oct 2004 Posts: 61 Location: Riga, Latvia
|
Posted: Fri Mar 25, 2005 4:03 am |
first thing i tried like i said in original post.
drops entire @liste2 instead of just phase spider part. for whatever reason !%ismember( "%i", @golemliste ) matches everything but works fine if i specify "stone golem" manually rather than fetching from %i |
|
|
|
DeReP Adept
Joined: 14 Jun 2003 Posts: 222 Location: Chile
|
Posted: Fri Mar 25, 2005 5:43 am |
maybe try it without the quotes in it?
#FORALL @liste2 {#IF (!%ismember(%i,@golemliste)) {#DELITEM liste2 %i}} |
|
|
|
hav Wanderer
Joined: 05 Oct 2004 Posts: 61 Location: Riga, Latvia
|
Posted: Fri Mar 25, 2005 6:58 am |
DeReP, please read my original post. things I tried, %i, "%i", {%i} as well as later '%i'. I'm at wits end on this one. Syntax looks about right, it should work.
Alternative approach I implemented, klutzy and involving two temp vars
#VAR t %numitems( @liste2)
#LOOP 1,@t {
#VAR t2 %pop( liste2)
#IF (%ismember( @t2, @golemliste)) {#VAR liste2 %additem( @t2, @liste2)}
}
it just doesnt like the %i part in #forall i dodged using |
|
|
|
Hazmeech Novice
Joined: 27 Mar 2005 Posts: 31
|
Posted: Sun Mar 27, 2005 6:07 pm |
Code: |
#CLASS {test}
#ALIAS golem {
#FORALL @Liste2 {
#IF !%IsMember( %I, @GolemListe) {
#ECHO -
#ECHO No Match ~"%I~"
#ECHO Good for deletion
} {
#ECHO -
#ECHO Matches ~"%I~"
#ECHO Keep this one
}
}
}
#VAR golemliste {rope golem|straw golem|clay golem|wood golem|stone golem|flesh golem|iron golem|crystal golem|diamond golem}
#VAR liste2 {stone golem|phase spider}
#CLASS 0
|
typing Golem Worked for me |
|
|
|
Hazmeech Novice
Joined: 27 Mar 2005 Posts: 31
|
Posted: Sun Mar 27, 2005 7:21 pm |
Oh yes, the only thing I saw really different between what I did and what you did is the,
#if (!%ismember(whaterver)) "what you did" and
#if !%ismember(whatever) "what I did"
Your case is good if you want to put a boolean expression like or, and etc..,
#if (!%ismember(whatever) & %ismember(Whatever)) {then go get'em}
if you don't have boolean expression don't use the bracket before the !.
That's how I see it anyways. |
|
|
|
hav Wanderer
Joined: 05 Oct 2004 Posts: 61 Location: Riga, Latvia
|
Posted: Tue Mar 29, 2005 7:17 am |
7.04 issue, was too lazy to upgrade. who knew minor version would make a difference, version history didnt mention any important changes for me.
should have known. sorry for bother people |
|
|
|
|
|