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
Churlant
Novice


Joined: 17 Oct 2002
Posts: 44
Location: USA

PostPosted: Wed Dec 12, 2007 4:49 pm   

Nester #IF triggers
 
I'm setting up an object listing script that grabs the name of objects taken from a corpse and adds it to a list. The script actually looks at the first four words in the object name, checks them against a list of non-keywords ("small", "large", "a", "the", etc), and captures the first viable keyword in the given string. The script as is works okay, but it seems somewhat cumbersome.. and since I have a habit of making things more difficult than they need to be, I thought I'd post what I have and ask for suggestions on making it more efficient / streamlined, if possible.

Quote:

#VA obj_check {red|blue|yellow|green|silver|black|brown|pink|white|orange|purple|a|an|from|the|or|for|of|scary|tattered|bloody|shiny|clean|slimy|thin|slim|pointy|sharp|dull|moldy|plain|giant|large|huge|big|small|tiny}
#TR {^You get (%w) (%w) (%w) (%w) * corpse of a *.$} {#IF (%ismember(%1,@obj_check)) (#IF (%ismember(%2,@obj_check)) (#IF (%ismember(%3,@obj_check)) (#IF (%ismember(%4,@obj_check)) (((%additem(%1,@obj_list)) (%additem(%2,@obj_list)) (%additem(%3,@obj_list)) (%additem(%4,@obj_list))))


And yeah, I do intend to have duplicate names on the list, hence the %additem function.

-JC
_________________
>-Churlant-<
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 12, 2007 5:19 pm   
 
First off, your %additems won't work because you can't start a command with a function reference. You'll need to put either #CALL or #NOOP in front of it for it to work correctly. Either that, or use obj_list=%additem(%2,@obj_list).

However, for the trigger, why not try it this way?

#TR {^You get (*) corpse of a *.$} {#LOOP 1,4 {#IF (%ismember(%word(%1,%i), @obj_check)) {obj_list=%additem(%word(%1,%i),@obj_list)}}

That should accomplish what you're trying to do. *shrug*

Charneus

EDIT: I made it to where it'll only check the first four words. :P
Reply with quote
Churlant
Novice


Joined: 17 Oct 2002
Posts: 44
Location: USA

PostPosted: Wed Dec 12, 2007 5:59 pm   
 
ehhh.. yeah, about the function reference you're right. I'm scripting at work and my 30 day trial on the zmud I dl'd ran out, so I haven't been able to actually test the code until I can get my reg key from the version I have at home copied over.

As to the improvement.. I appreciate it. That kind of reduction in code is what I was looking for. First 4 should be fine for almost everything except the most inane area builder ("You get an extremely small and sharp green poisoned dagger from the corpse of a wino.") isn't out of the question I suppose Shocked

-JC
_________________
>-Churlant-<
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 12, 2007 6:07 pm   
 
If I understand this you are looking to trigger off of a line like "You get the amazing holographic scepter of imagining from the corpse of a dog." Then you want to take the part "the amazing holographic scepter of imagining" and try to determine a keyword. The way to do this best is first capture the entire thing then eliminate obviously useless words.
Code:
#CLASS KeyWordDeterminer
#VAR UselessWords {an?|and|the|of|for|.*?ly}
#VAR GoodWords {scepter}
#REGEX {^You get (?:an? |the |)(.*?) from the corpse of} {
 #VAR ItemPhrase {%1}
 ItemPhrase=%subregex(@ItemPhrase,%concat("\b(?:",@UselessWords,")\b")," ")
Now you are down to a short list of possibly good words. Generally your keyword is a noun and since the English language puts adjectives and adverbs before nouns you are more likely to get your keyword starting with the last word in the string rather then the first. The %subregex I used has created the possibility of extra blank spaces so we clean that up, then start from the back.
Code:
 ItemPhrase=%subchar(@ItemPhrase,"| "," |")
 #DELITEM ItemPhrase {}
 Counter=%numitems(@ItemPhrase)
 #WHILE ((@Counter>0)&(%ismember(%item(@ItemPhrase,@Counter),@GoodWords)=0)) {#ADD Counter -1}
Now we check to see if it found a word or failed out.
Code:
 #IF (@Counter) {
  obj_list=%additem(%replace(%item(@ItemPhrase,@Counter)," ","|"),@obj_list)
 } {
  ItemPhrase=%subchar(@ItemPhrase," |","| ")
  #SHOW Failed to determine keyword from known list for @ItemPhrase
 }
}
#CLASS 0
That is about how I roughly do it in my scripts now. I have further checking so that it tests the determined keyword and records an actual one so that it doesn't have to search in the future. I also tend to add any keyword found into my GoodWords list for later usage.

To attempt to make use of this script copy all the portions in the seperate code blocks together as a single command line entry.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Churlant
Novice


Joined: 17 Oct 2002
Posts: 44
Location: USA

PostPosted: Wed Dec 12, 2007 8:18 pm   
 
Vijilante... I really appreciate the ideas, but they're waaaay over my head. I can more or less follow along with Charneus's example, but yours is way too tech for me. Embarassed
_________________
>-Churlant-<
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 12, 2007 9:05 pm   
 
Churlant, Vijilante is that way with everything. His GURU title isn't even appropriate. I wouldn't be surprised if even Zugg is baffled by Viji's know-how. He's a zMUD God, as far as I'm concerned. :P Glad my example works out for you. But later on down the road, you may want to learn to decipher Viji's scripts. He has some VERY good ones, and you can learn a lot. Also, if you need to get it to work for extremely long phrases such as the one you pointed out, you /could/ change the #LOOP 1,4 to #LOOP %numwords(%1) and it'll search the entire thing before corpse. :P Just an idea.

Charneus
Reply with quote
Churlant
Novice


Joined: 17 Oct 2002
Posts: 44
Location: USA

PostPosted: Wed Dec 12, 2007 11:01 pm   
 
I don't doubt Vijilante is genius... but I'm not so sure I'll ever need that level of complexity for anything I'll do in-mud. Hell, I don't even know more than half of the functions/commands he listed. It's like I'm building a soapbox car while he's giving me tutorials on ion propulsion. Laughing
_________________
>-Churlant-<
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 12, 2007 11:21 pm   
 
Probably the only thing new in there is %subchar and %subregex. Also I am most definitely not a god since there script is missing a closing brace, and therefore I have erred. Gods don't make mistakes.

On average I would say the 2 scripts will finish in about the same amount of time. The use of #LOOP doesn't allow for the script to end early, and can cause multiple words to be recorded for a single item. That likely isn't a bad thing. My script, on the other hand, will only record 1 word per item. It may also record none because it requires a list of GoodWords. If you want all words except for the bad ones kept then it becomes even easier.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Dec 13, 2007 1:21 am   
 
Through talking with Churlant (found out he plays the same MUD as I do), I found out he's needing more than that. The finished code actually looks like this now:

Code:
#TRIGGER {^You get (*) corpse of *.$} {#LOOP 1,4 {#IF (%ismember( %word( %1, %i), @obj_check)) {} {#IF !@objtemp {#ADDITEM objtemp %word( %1, %i)}}};obj_list=%additem( @objtemp, @obj_list);#UNVAR objtemp}


With the second #IF check, it'll only put one keyword in the obj_list. *shrug*

Charneus

By the way, Vij, know anyone who wants to convert ALL my zMUD scripts to CMUD (for free!?) :P
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