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
Alchemist
Newbie


Joined: 11 Nov 2009
Posts: 5

PostPosted: Wed Nov 11, 2009 4:27 pm   

Multiple issues with lists, comparisions, and negation - Help Please!
 
I want to capture each line of text, compare it to a list, and if it doesn't match the list perform an action.

So far I tried some regular expression, It worked somewhat but some items weren't triggering correctly. Having to perform the action when it didn't match my trigger string was failing, and the actual trigger became way too long so I thought I'd try a list which is more manageable.

I recently made a trigger for &test, which stores each line into a variable called @test.

I tried to use that variable to compare it to a list but that didn't work either.

#IF (@test =~ @MainList) {}{#BEEP}

I was thinking that each line would store itself in @test, run the comparison, then the next line would overwrite @test, run the comparison, and so on.

I'm guessing this can be done several ways but the lists don't seem to be comparing correctly.

Any help would be appreciated, I don't care what method is used just that it works!
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Nov 11, 2009 4:40 pm   
 
Actually, there's a much simpler way to match your @MainList.

#TRIGGER {{@MainList}} {#BEEP}

Then, only when a line matches an item in your MainList variable, it'll fire. No need to say '#IF (this=that) {} {#BEEP}', though I'm assuming you want it to BEEP on the lines it does match.

Charneus
Reply with quote
Alchemist
Newbie


Joined: 11 Nov 2009
Posts: 5

PostPosted: Wed Nov 11, 2009 4:46 pm   
 
Actually I want it to trigger when it doesn't match :)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Nov 11, 2009 5:22 pm   
 
#if (!%ismember("%1",@MainList)) {#beep} {#noop do whatever you want to do with anything in @MainList}
_________________
EDIT: I didn't like my old signature
Reply with quote
Alchemist
Newbie


Joined: 11 Nov 2009
Posts: 5

PostPosted: Wed Nov 11, 2009 7:56 pm   
 
Thanks, works like a charm. Now I just have one issue preventing it from being perfect.

For some reason I get a "> " that shows up whenever I send a command to a mud. I'm assuming this is just the mud representing a carriage return.
For example

Event
Event
Command from me
> Event

This is messing up my list since I have Event in there but not "> Event"

Are there any settings that can get rid of this? Or can I modify either the list or trigger to accomodate for the possible "> "

Edit: Actually in general how would I add more flexible pattern matching to my list as far as wildcards.
I'd rather not have to put "You see a dog|You see a cat|You see a horse" in the list. Just "You see a *". A list doesn't seem to want to take wildcards though.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Nov 11, 2009 9:48 pm   
 
As I just posted to your other thread, > seems to be your game's prompt.

A list is able to take "simple" wildcards, but you may need to check preferences to make sure the option is enabled (it will say something about wildcards in stringlists). You can use * and any wildcard that starts with %, but you can't use a stringlist or range within a stringlist:

This is ok
You see {%d|a %w|an %w|some %w}

This is not ok
You see {{a duck|%d ducks}|something other than ducks}
You see {[abcd]|[efgh]}
_________________
EDIT: I didn't like my old signature
Reply with quote
Alchemist
Newbie


Joined: 11 Nov 2009
Posts: 5

PostPosted: Thu Nov 12, 2009 12:30 am   
 
I went through the settings like 10 times and the only thing I saw that might be it is under Script Parser > General Parsing: Wildcards in {} triggers, which I enabled but I don't think that is what I'm looking for.

Here's my current setup with some test data. If any input is in the list, it does nothing. If it isn't in the list, I get a beep and it's sent to a different window.

Also the problem with my prompt is that any of the input may have a "> " in front of it.

pattern: &test
value: #if (%ismember(@test,@List_1)) {#noop} {#beep;#cap whitelist}

List_1: (text style)
You hit Bob with your sword.|You hit Joe with your sword.|You're hungry|What?|* You have gained 50 exp.|Your strength has increased|Your attack power has increased

When I'm looking at the List_1 variable in string list style it looks like this:

1 You hit Bob with your sword.
2 You hit Joe with your sword.
3 You're hungry
4 What?
5 * You have gained 50 exp.
6 Your strength has increased
7 Your agility has increased

I tried to apply what you said above but I must be doing something wrong. I would like to be able to set it to where the list is something like:
You hit * with your sword.||You're hungry|What?|* You have gained * exp.|Your * has increased

1 You hit * with your sword.
2 You're hungry
3 What?
4 * You have gained * exp. (<-once I enable wildcards I'd have to escape the first * since it is not meant to be a wildcard, correct?)
5 Your * has increased

I tried changing the List first to accept wildcards and it didn't work.
{You hit %w with your sword.||You're hungry|What?|* You have gained * exp.|Your * has increased}

Ultimately I want something like the below that can allow either nothing or the "> " string prior to all the items in the list.
{|> }{You hit * with your sword.||You're hungry|What?|* You have gained * exp.|Your * has increased}

Neither worked right or accepted wildcards.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Nov 12, 2009 3:36 am   
 
Quote:

I went through the settings like 10 times and the only thing I saw that might be it is under Script Parser > General Parsing: Wildcards in {} triggers, which I enabled but I don't think that is what I'm looking for.


Ah, you want that for matching a list in code (no preference for it, since it's "always on"). That's different, though it too can be easily done using pretty much the same rules as the preference. You won't be able to do it directly via stringlist, though.

#trigger {^{|> }&test$} {#forall @List_1 {#if (%match(@test,"%i")) {#noop} {#beep;#cap whitelist}}}

That should work fine for line capture, but if you want to do something useful with the line you may want to rethink your approach.
_________________
EDIT: I didn't like my old signature
Reply with quote
Alchemist
Newbie


Joined: 11 Nov 2009
Posts: 5

PostPosted: Fri Nov 13, 2009 10:53 pm   
 
You're the man, thanks for the quick responses too! I didn't think of adding the {|> } in the actual pattern. Oh if you don't mind what does the "%i" do in that statement exactly?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Nov 13, 2009 11:36 pm   
 
%i refers to the current element as defined by a looping structure. In this case, that would be the #forall command and the contents of %i would be the same as %item(@test,#) where # was the number of the element. For things like #LOOP, it's the number of the current iteration.

There's a whole series of counter variables like this, allowing you to refer to any level of nested looping structures. It starts with %i, then goes forward in the alphabet, using any letter that is not already defined within the context of %1...%99 variables (ie, it won't use %x or %t because %x1...%x99 are used with #PSUB/#PCOL commands and %t1...%t99 are used to refer to %1...%99 variables from other trigger states in a multi-state trigger.)
_________________
EDIT: I didn't like my old signature
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