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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Tue Jun 28, 2011 10:11 pm   

Imported script issue with %grep
 
I have an old text file I made while still using zMUD many years ago, and a few aliases that allowed me to search that text file and return the result I was looking for, but I can't get it to work properly in CMUD. I've narrowed it down to the %grep I think, but I can't figure out what's wrong with it.

The file is a long list of mobs in my MUD. The alias is as follows:

Code:
#FILE 2 script_moblist.txt
#VAR mobsearch_matches %grep( 2, "%-1")
#SAY -MobSearch-
#IF (!@mobsearch_matches) {
  #SAY No matches found for --> ~"%-1~"
  #VAR mobsearch_matches {No matches}
  } {#IF (%numitems( @mobsearch_matches) > @mobsearch_numresult) {
    #SAY Too many matches.
    #SAY Outputing first @mobsearch_numresult matches:
    #LOOP @mobsearch_numresult {#SAY %pop( mobsearch_matches)}
    } {
    #SAY Mobs matching '%-1' are:
    #FORALL @mobsearch_matches {#SAY %i}
    }}
#CLOSE 2


This always matches the entire file for some reason, not just the search string I'm looking for. I'm pretty sure the issue is with my "%-1" in the first %grep, but I can't seem to figure out what to replace that with to make it work again.

Any ideas? Thank you for your time.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Jun 28, 2011 11:05 pm   
 
Take the %-1 out of quotes. In cmud, when you put something in quotes, it means treat it as a literal string, and thus it's not being expanded. That should mean it's searching the file for the actual sequence of characters %-1, so I'm not sure why it's returning the entire file (unless you have that on every line), but regardless, %grep(2, %-1) should do what you want.
Reply with quote
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Wed Jun 29, 2011 3:51 am   
 
Tried that already. The %grep(1,"string") still has the quotes shown in the helpfiles, but that could be a remnant of zMUD, but I thought the same thing so I tried that first. No luck unfortunately. :/
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Jul 01, 2011 10:37 am   
 
Well yes, because in that example it's searching for an actual string. In your case, you're not - you're searching for the contents of a variable, and you want that variable to expand. I don't know why it won't work, I'm afraid...
Reply with quote
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Sun Jul 03, 2011 1:41 am   
 
After looking at it more closely, it appears that the %grep may not be the problem - I tested it with a new alias by itself, and it worked as intended. Could is possibly be the

Code:
#IF (!@mobsearch_matches) {
  #SAY No matches found for --> ~"%-1~"
  #VAR mobsearch_matches {No matches}
  } {#IF (%numitems( @mobsearch_matches) > @mobsearch_numresult) {
    #SAY Too many matches.
    #SAY Outputing first @mobsearch_numresult matches:
    #LOOP @mobsearch_numresult {#SAY %pop( mobsearch_matches)}
    } {
    #SAY Mobs matching '%-1' are:
    #FORALL @mobsearch_matches {#SAY %i}
    }}


statement? Every thing I search for, even gibberish, results in the 'else' commands being echoed. Maybe the ! operator has changed or something? #IF (!@mobsearch_matches) always results in the #SAY Too many matches. section, regardless of input. I'm stumped.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Jul 03, 2011 2:12 am   
 
Well, is the mobsearch_matches variable ever empty? You said above that the %grep is always returning the entire file, if that's the case then it would make sense that the else part would always be run...
Reply with quote
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Mon Jul 04, 2011 12:00 pm   
 
It is redefined at the beginning of the alias. Deleting the variable and then entering the alias to recreate it ends with the same result - the entire file (all 900-something lines/mobs) is matched and saved in the variable, and then output (limited only by the @mobsearch_numresult variable, to prevent my window from being spammed with all 900-something lines. What I can't figure out is why the entire file is being matched, regardless of what I search for. For example, if I search for


Code:
A 15 headed hideous monster


or even just
Code:
15 headed


it should return only
Code:
>A 15 headed hideous monster                            XP: 5140929 - F - Drops: Gloomy Gloves


because that is the only line in the entire file that contains that string. Instead, the result is always:

Code:
-MobSearch-
Too many matches.
Outputing first 10 matches:
>1st circle Samurai defends the castle                  XP: 10211 - Area: Castle Broxima
>2nd circle Samurai just train martial arts             XP: 58964 - Area: Castle Broxima
>2nd circle Samurai just trains martial arts            XP: 152616 - Area: Castle Broxima
>4th circle samurai Gordo sneaks around and looks for intruder XP: 2151203 - Area: Castle Broxima
>A 15 headed hideous monster                            XP: 5140929 - F - Drops: Gloomy Gloves
>A 2nd order priest of Starwind                         XP: 259822 - Area: Stargrove
>A 3rd order priest of Starwind                         XP: 398453 - Area: Stargrove
>A 9 tentacled virgooth                                 XP: 79050 - Area: Frogmen Camp
 Note: Loses tentacles throughout battle
>A beautiful Amazon warrior                             XP: 983 - F


as if all lines contained "15 headed".
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Jul 04, 2011 3:18 pm   
 
Well, I copied that small part of your file into a new text file, and saved it in my session directory as script_moblist.txt. I created a new alias, mobsearch, and copy/pasted in your code from the first post (removed the quotes around the %-1 in the %grep). I created a new variable called mobsearch_numresult, and gave it a value of 10. Then I typed mobsearch 15 headed on the command line, and got this:
Code:
Opened script_moblist.txt as file 2
-MobSearch-
Mobs matching '15 headed' are:
>A 15 headed hideous monster                            XP: 5140929 - F - Drops: Gloomy Gloves
Closed C:\Program Files\CMUD\aard\script_moblist.txt on file 2

So the only thing I can think of is that something else must be interfering with it. Have you tried testing it on a clean session?
Reply with quote
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Mon Jul 04, 2011 6:45 pm   
 
So strange. I renamed the old alias "old_mobsearch", made a new one named "mobsearch", then copied and pasted the exact contents of the old alias in to the new one, and it works just as it used to - the first time. Any repeated attempts make the same result, matching the whole file.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Jul 04, 2011 9:25 pm   
 
Did you try testing it on a brand new session? I can't get your code to fail, so I think it might be something else interfering with it. For example, is it possible you have a duplicate mobsearch_matches variable? The grep could be storing the correct results in one mobsearch_matches, then the contents of the other mobsearch_matches, which happens to contain the entire file, are displayed. Running it on a clean session with no other settings but that one alias installed would help rule out problems like that.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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