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


Joined: 17 Feb 2007
Posts: 48

PostPosted: Sun Apr 13, 2008 3:53 pm   

Trouble with getting variable values from triggers
 
I have a couple triggers to capture some veriables however I'm missing something and I don't get what I want.

The triggers are:
Code:

#trigger {^Object: (*)  $} {#var ObjectName {%1}}
#trigger {^Object: (*)  Item type: (*)  $} {#var ObjectName {%1}; #var ItemType {%2}}
#trigger {^Object: (*)  Worn: (*)  $} {#var ObjectName {%1};#var ItemWorn {%2}}
#trigger {^Object: (*)  Worn: (*)  Item type: (*) &} {#var ObjectName {%1};#var ItemWorn {%2};#var ItemType {%3}}


Obvisouly the object name can be a couple words or just one. The values I get afterwards though look like this.

text to trigger:
Object: a sparkling potion Item type: Potion
@ObjectName = a sparkling potion Item type: (incorrect)
@ItemType = Potion

Another example:
Object: a Gateway of Dimensional Shift Item type: Other
@ObjectName = a Gateway of Dimensional Shift Item type: (Incorrect)
@ItemType = Other

Another Example:
Object: Spine Seeker Worn: Wield Item type: Weapon
@ObjectName = Spine Seeker
@ObjectWorn = Wield Item type: (incorrect)
@ItemType = Weapon

Anoher example
Object: a floating disc of weight negation Worn: Hold Item type: Container
@ObjectName = a floating disc of weight negation
@ObjectWorn = Hold Item type: (incorrect)
@ItemType = container

Ideas?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Apr 13, 2008 4:57 pm   
 
The problem is that your first trigger matches the text that all the rest of your triggers do. Because it fires last, it's overwriting what the other triggers set. You should use a single regex for them all with a non-greedy quantifier. I can't in into more detail about that because i'm on my phone right now and typing out the symbols will ae annoying. Hopefully someone else can help with that, or you can find it yourself on regular-expressions.info.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Winslow
Novice


Joined: 17 Feb 2007
Posts: 48

PostPosted: Sun Apr 13, 2008 5:09 pm   
 
I'm not too savy zScript so don't entirely follow. I do understand the problem but not the solution. Is there a way to reverse the order in which the triggers fire so I don't have one overwritting the rest? Or Have the first trigger capture all words up to "Worn" or "Item" as these would not be in the object name itself?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sun Apr 13, 2008 5:22 pm   
 
This will turn it into a record variable with the fields properly set. Get rid of the rest of your tiggers.
Code:
#trigger {^Object: (*)  $} {#var Object {};#ADDKEY Object {%concat("Name=",%replace(%replace("%1"," Worn: ","|Worn=")," Item type: ","|Type=")))}}

_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Winslow
Novice


Joined: 17 Feb 2007
Posts: 48

PostPosted: Sun Apr 13, 2008 6:30 pm   
 
Thanks. I tried this and doesn't seem to work.

The context can be;

Object: blah
or
Object: blah Item Type: blah blah
or
Object: blah Worn: blah blah
or
Object: blah Worn: blah blah Item Type: blah blah blah

If it matters, there are two spaces between the end of name and next catagory. (i.e. object and worn). It can be any of the above 4 patterns too. Also, in the above code, I can't exactly tell what ones you are using as the veriable names. That could be my problem too. Sorry, but I am quite a nooooob.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Apr 13, 2008 7:04 pm   
 
I hope you appreciate how damn annoying this was to type out on a phone keypad. I knew i should've brought my laptop :( this is obviously untested.

Code:
#regex {^Object: (.*?) (?: Worn: (.*?) )?(?: Item type: (.*?) )?$} {ObjectName=%1;ObjectWorn=%2;ItemType=%3}


If this doesn't match, try removing the $ or the ^ or, if all else fails, both.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Winslow
Novice


Joined: 17 Feb 2007
Posts: 48

PostPosted: Sun Apr 13, 2008 7:22 pm   
 
Heh, that's laughably impressive. But I can't get it to match :P

text is:
Object: a floating disc of weight negation Worn: Hold Item type: Container

values come to:
@ObjectName =
@ObjectWorn =
@ItemType =

When coping and pasting the above exact text, it only looks like one space between the completion of the name and the next category. Through my zMud screen, it looks like two so it could be some other invisible character.
Reply with quote
Winslow
Novice


Joined: 17 Feb 2007
Posts: 48

PostPosted: Sun Apr 13, 2008 8:25 pm   
 
Woo, I just worked it out!

instead of using the "*" wild card in every case, I replaced this, were I could, with %w to capture one word. Then had used {^string} to not match the patterns with the words "Worn:" or "Item Type:" Thanks for your direction though guys and thanks to Fang for putting up with me. Laughing
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