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
Posideon
Beginner


Joined: 06 Feb 2005
Posts: 26

PostPosted: Fri Jan 11, 2008 7:06 pm   

Local Variable in the trigger pattern
 
Is there a way to create a local variable off the trigger pattern like using the &variable to make a regular variable. I'm trying to create a trigger that will take all the gold silver and copper I get from selling stuff and telling me how much total I made.


Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="19280">
    <pattern>{Shopkeeper|Merchant} gives you {$goldsell gold|$goldsell gold $silversell silver|$goldsell gold $silversell silver $coppersell copper|$goldsell gold $coppersell copper|$silversell silver $coppersell copper|$silversell silver|$coppersell copper} for</pattern>
    <value>#variable sellgold {%eval($goldsell*100 + $silversell*10 + $coppersell)}
soldfor</value>
  </trigger>
</cmud>

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="soldfor">
    <value>#say %ansi(7)You have now sold shit for a total of %ansi(14)@SellGold gold%ansi(7).</value>
  </alias>
</cmud>



Quote:

Shopkeeper gives you 10 gold for dark leather tunic
Shopkeeper gives the item to a clerk in the storeroom.
Shopkeeper haggles with you over the price of dark leather ankleband.
Shopkeeper gives you 2 gold 5 silver for dark leather ankleband
Shopkeeper haggles with you over the price of dark leather belt.
Shopkeeper gives you 3 gold 6 silver for dark leather belt
Shopkeeper gives the item to a clerk in the storeroom.
Shopkeeper haggles with you over the price of battered iron shortsword.
Shopkeeper gives you 5 gold for battered iron shortsword
Shopkeeper haggles with you over the price of dark leather gloves.
Shopkeeper gives you 2 gold 5 silver for dark leather gloves


That's what I have so far. The problem is I could get gold silver and copper or just gold and copper or gold and silver or any combinations. Gold=100 copper, silver=10 copper, so I can get an output in all copper which would be fine, while creating a variable for each would work, love to use new settings and the localvariable here seems like the best bet.

Thanks,
Posideon
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Jan 11, 2008 7:24 pm   
 
Try this regex:

(Shopkeeper|Merchant) gives you (?:($goldsell:\d+) gold )?(?:($silversell:\d+) silver )?(?:($coppersell:\d+) copper )? for

This (localvar:wildcard) syntax is the proper way to refer to local variables in patterns, and (something)? means that it can be the word "something" or nothing.

I had to use a regex because you can't use wildcards inside CMUD's {something|something else} syntax.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Posideon
Beginner


Joined: 06 Feb 2005
Posts: 26

PostPosted: Fri Jan 11, 2008 7:29 pm   
 
Thank you Fang Xianfu. Is there a way to trigger local vars in the pattern with CMUD's syntax if it's not in the {something|something else}? I know it will come up in plenty of other situations.

Thanks a ton,
Posideon
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Jan 11, 2008 7:33 pm   
 
Yep, just use ($localvar:wildcard) like I did in that regex.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Posideon
Beginner


Joined: 06 Feb 2005
Posts: 26

PostPosted: Fri Jan 11, 2008 7:50 pm   
 
What you wrote for me Fang isn't working it's not matching the pattern... not sure what to do Sad
Reply with quote
Posideon
Beginner


Joined: 06 Feb 2005
Posts: 26

PostPosted: Fri Jan 11, 2008 8:04 pm   
 
Whoops I didn't set it as a regular expression. Pattern is matching now, but it doesn't seem to be setting the local variables.

Code:

Shopkeeper gives you 12 gold 123 silver 23 copper for


Code:

%1 : Shopkeeper
%2 : 12
$goldsell : 123
%4 : 23


That is what I get when I go to test pattern matching
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Jan 11, 2008 8:35 pm   
 
I made a mistake in the regex (extra space, and I also forgot to make the first brackets non-capture), you should use this one instead:

(?:Shopkeeper|Merchant) gives you (?:($goldsell:\d+) gold )?(?:($silversell:\d+) silver )?(?:($coppersell:\d+) copper )?for

As for the captures not capturing, I have no idea what could be causing it. It works fine with simpler triggers - seems like a bug.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Posideon
Beginner


Joined: 06 Feb 2005
Posts: 26

PostPosted: Fri Jan 11, 2008 8:39 pm   
 
This is matching now, but instead of $goldsell it's giving me %1, instead of $silversell it's giving me %2, and instead of $coppersell it's giving me $goldsell... I don't know how regex works...so umm fix it fix it fix it? Very Happy hehe thanks for everything so far though Fang
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Jan 11, 2008 8:44 pm   
 
Well, for now you can probably just remove the local variable references in the pattern and use %1-3 instead. If you actually need to use them as local variables (you're doing stuff with them later) then you can just do $goldsell=%1 and whatnot.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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