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
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Fri Nov 16, 2001 9:16 pm   

User defined functions
 
I'd like to write a function that takes a string as an argument, and returns that string with all instances of items from a certain string list removed. for example:


mob = "The monkey"
word_list = {The |A |An }
mob_to_hit = @strip_article(@mob)

and the value of @mob_to_hit would end up being "monkey"
i cant seem to figure out what the correct value for @strip_article should be. any advice is appreciated!

Emit
Reply with quote
Acaila
Apprentice


Joined: 30 Aug 2001
Posts: 187
Location: Netherlands

PostPosted: Fri Nov 16, 2001 9:55 pm   
 
This might be a little more complicated than you had in mind, but it's all I could think of atm.

#ALIAS stripmob {
#VARIABLE Mob_To_Hit %null
#VARIABLE Mob "%-1"
#VARIABLE Mob %replace( @Mob, " ", "| |")
#FORALL {@Mob} {#IF (!%ismember( %i, @Word_List)) {#VARIABLE Mob_To_Hit %additem( %i, @Mob_To_Hit)}}
#VARIABLE Mob_To_Hit %replace( %replace( @Mob_To_Hit, "|", ""), " ", " ")
}

What it does is save whatever you input after the alias into the variable @Mob. Then it checks that variable against the words in the @Word_List, and copies only those words into @Mob_To_Hit that aren't in @Word_List.

Acaila
Reply with quote
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Fri Nov 16, 2001 11:46 pm   
 
i wrote an alias that does the job like this:


#alias stripper {
#forall @words_to_strip {
mob_to_hit = %replace(@mob,%i,"")
}
}

but i was looking to make it a function so i could call it in the middle of another function call
i cant see how though, because i can't find a looping function, and i don't think you can put commands into custom functions, and i can't see how to do it without looping

Emit
Reply with quote
chiu
Newbie


Joined: 10 Oct 2000
Posts: 9
Location: China

PostPosted: Sat Nov 17, 2001 1:41 am   
 
Maybe Zugg need to add a command
"#return" for Usr-defind func.
Then we can use #func more freely.
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sat Nov 17, 2001 1:56 am   
 
A clumsy way of using a function to perform this would be the following:


#FUNCTION strip_article {%delitem("A", %delitem("An", %delitem("The", %replace(%1, " ","|"))))}

This converts the phrase into a string list then uses nested %delitem functions to seek out and remove the three articles. Obviously, as the number of articles grows, this function will become rather unwieldy.

Can you say with certainty that the last word in the phrase will always be the keyword? If so, this function will serve you:


#FUNCTION last_word {%word(%1, %numwords(%1))}


Troubadour
Reply with quote
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Sat Nov 17, 2001 3:16 am   
 
unfortunately, the key word is guaranteed not to be the last word and the real list of key words has about 8 words/phrases. i'll just use the alias, but thanks for the help anyway
Emit
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