Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Articnal
Apprentice


Joined: 19 Jan 2002
Posts: 107

PostPosted: Mon Dec 29, 2003 3:48 pm   

Lil sintaxis problem
 
Hi,i got a stringlist called objetive,the variable is @objetive.

I want to atack every element on that list,but some words like blood,an,a,or so.

I do:
#loop 1,%numitems(@objetive) {#if (%item(@objetive,%i)="a"|"blood"|"an") {kill %item(@objetive,%i)}}

That will ask to kill "a",and "an" too... Why?
How to get it to do what i want?
Other way could be using "=~ " instead of "=" but in that case,any word containing "a" or "an" will be omitted too.

Thanks for any help.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4692
Location: Pensacola, FL, USA

PostPosted: Mon Dec 29, 2003 3:55 pm   
 
Well you could just remove the items you dont want to attack from the list. Or if the stuff is needed on the list make a seperate stringlist for the things you do want to kill.
Reply with quote
Articnal
Apprentice


Joined: 19 Jan 2002
Posts: 107

PostPosted: Mon Dec 29, 2003 4:07 pm   
 
The stringlist Objetive is generated everytime I enter a new room,so i cant do that
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Mon Dec 29, 2003 5:50 pm   
 
This is the simplest way, you could add to it by using a String List to hold things to remove (for exapmle "a|the|an|"

But here's the general idea:

objective = a|blood|monster|the|an

Trigger Value:

loopcount = %numitems( @objective)
#LOOP @loopcount {#IF (%item( @objective, %i)= "a") {
#DELNITEM objective %i
#SHOW %i
}}
#FORALL @objective {#SHOW you kiled: %i}


results in a @object stringlist of: blood|monster|the|an

resulting in an output of:

you kiled: blood
you kiled: monster
you kiled: the
you kiled: an


You'd only have to change the #IF statement to loop through the "exluded" members list. I'm at work and doing this offline. If you need more help let me know and I'll see what i can come up with.
Reply with quote
Articnal
Apprentice


Joined: 19 Jan 2002
Posts: 107

PostPosted: Mon Dec 29, 2003 6:06 pm   
 
Thankyou,but i couldnt find out the solution to my problem from that text; Ill ask it other way:
How to do next if does the #echo yes?

#if ("Un"={"Un"|"el"|"la"|"de"}) {#echo yes}

If i substitude = with =~ ,that will work,but will also work everytime any word containing "Un" or "el",etc,is on the list.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Mon Dec 29, 2003 6:07 pm   
 
You only have a minor syntax error in your IF statement. You have: kill %item(@objetive,%i) in the true field of the if statement.
Just change the IF statement to:
#if (%item(@objetive,%i)="a" OR "blood" OR "an") {} {kill %item(@objetive,%i)}

And it should work.
Reply with quote
Articnal
Apprentice


Joined: 19 Jan 2002
Posts: 107

PostPosted: Mon Dec 29, 2003 6:32 pm   
 
It works,thanks u all =)
Reply with quote
Articnal
Apprentice


Joined: 19 Jan 2002
Posts: 107

PostPosted: Mon Dec 29, 2003 8:14 pm   
 
#if ("Uonjk"="Un" OR "el") {#echo yes}
--> that echos yes
#if ("Un"="Un" OR "el") {#echo yes}
--> that too

What now?? =(
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Dec 29, 2003 9:41 pm   
 
The best thing to do is make an exclusion list. For example:
#VAR ExcludedObjetives {a|an|the|blood}
Then in your alias to do the attacks:
#IF (%ismember(%item(@Objetive,%i),@ExcludedObjetives)) {#NOOP} {kill %item(@objetive,%i)}
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Dec 29, 2003 11:44 pm   
 
Something everyone seems to have missed is that no matter whether you use | or OR, each comparison must be done separately. This won't affect Vijilante's solution since he's checking for membership in a list instead of comparing strings.
Original:
#if ("Uonjk"="Un" OR "el") {#echo yes}
Grouped to show actual order of operations:
#if (("Uonjk"="Un") OR ("el")) {#echo yes}
You are checking to see if "Uonjk" matches "Un" (no) or if "el" is a non-null string (yes). Since "el" is always a non-null string, you always have a yes for that side of the OR, so you always #echo yes.

Revised:
#IF ("Uonjk"="Un" OR "Uonjk"="el") {#echo yes} {#ECHO no}
This will now echo no, since "Uonjk" doesn't match either "Un" or "el".
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net