 |
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: 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? |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
 |
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: 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?
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: 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 |
|
|
 |
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: 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. |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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. |
|
|
 |
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: 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. |
|
|
 |
Winslow Novice
Joined: 17 Feb 2007 Posts: 48
|
Posted: 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.  |
|
|
 |
|
|