|
dguevara Newbie
Joined: 08 Oct 2008 Posts: 9
|
Posted: Wed Oct 08, 2008 5:05 pm
Cmud help |
Hi, im trying to set up a simple trigger but im running into troubles on how the regex is implemented in zscript
Code: |
#echo test %match("a","a"|"b");
#echo test %match("a","a|b"); |
if i want this %match funtion to evaluate options, how can i make this possible?
And if someone could post some examples of settings built using jscript or vbasic, it would be greatly apreciated, im fluent in both but i dont know how to begin using them with cmud |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Oct 08, 2008 5:15 pm |
The %match function doesn't use regex, it uses the simpler zScript pattern syntax. However, you can do what you're after with this function by putting the captures into a variable so you can do something else with them, you could do something like:
#echo test %match("test","(%w)",$var) value: $var
which will print "test 1 value: test". This example uses a local variable - you can use a global variable in the same way:
#echo test %match("test","(%w)",var) value: @var
That's about it really.
You'll might find the %regex function or %subregex (which has considerably more options) to be more useful.
However, it's likely there's a better way to do what you're trying to do, and there's probably an alternative method that'll be simpler, and probably faster too, because both %match and %subregex have to compile the regex before they try to make a match. If you explain the actual problem you're trying to solve, we can suggest some alternatives. |
|
|
|
dguevara Newbie
Joined: 08 Oct 2008 Posts: 9
|
Posted: Wed Oct 08, 2008 8:37 pm |
Thanks a lot for helping, yeah I assumed that when the api talked about "pattern" it would accept a regex inside.
My goal is to make a equipment database class, that captures when active the output of a spell or a scroll.. for example;
Code: |
You recite a scroll of identify which turns to dust in your hands.
a bloody diamond badge crafted by Boko weighs 0 pounds and is worth roughly 26 platinum, 7 gold, 4 silver, and 4 copper.
The following abilities are granted when using this item:
DET_GOOD DET_MAGIC
The item is able to float on water.
This item also affects your:
AGI_MAX by +1
HITPOINTS by +8 |
Code: |
You recite a scroll of identify which turns to dust in your hands.
a decent electrum broadsword of fear weighs 4 pounds and is worth roughly 18 platinum, 2 silver, and 8 copper.
The following abilities are granted when using this item:
DET_EVIL
The item is magical and able to float on water.
This item appears to be imbued with some magic beyond your comprehension!
You magically sense that the damage dice for this weapon are '5D4'
This item also affects your:
DAMROLL by +3
HITROLL by +2
WIS_MAX by +2
|
Code: |
You complete your spell...
an icy softwood veil weighs 2 pounds and is worth roughly 4 platinum, 5 gold, and 1 silver.
The item is able to float on water.
This item also affects your:
CON_MAX by +1
|
as you can see the results may vary in length, and i want to capture and display a format like this: "a decent electrum broadsword of fear|5d4|dam +3|hit +2|wis_max +2"
So my idea was to capture all lines, and parse them into a database with all possible fields, and whenever called just display whats been filled. My first attempt using zScript(im new to it) was this
Code: |
#trigger {You recite a scroll of identify which turns to dust in your hands.$}{#T+ ider;}
//class ider
// used a trigger that matched empty line to note when the id ends
#trigger {$}{
#T- ider;
#VAR itr 0;
#Echo @itr;
#while (@itr < 10) {
#IF (%match(%line(@itr),"((You recite a scroll of identify which turns to dust in your hands.)|(You complete your spell...))"))
{
#echo Capture from line 0 to line @itr
#break;
}
itr = @itr +1;
}} |
I have not started the parsing code, or the database insertion however any assistance would be apreciated or some examples on proper coding using zScript, jScript, vBasic or lua. Dont really know how to integrate any of them with cmud besides zScript. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Oct 09, 2008 7:35 am |
This is quite a common problem and there's an easier way to do it using multistate triggers. Perhaps:
#trig {You recite a scroll of identify which turns to dust in your hands.$} {#var IDItem ""}
#cond {($name:.+) weighs ($weight:\d+) pounds and is worth roughly ($w_plat:\d+) platinum, ($w_gold:\d+) gold, and ($w_silver:\d+) silver.} {Do whatever you like with the variables to store them. I'd do something like: #addkey IDItem Name $name;#addkey IDItem Weight $weight and so on, using a data record variable. You can plug those straight into CMUD's database module if you want} {regex}
#cond {The following abilities are granted when using this item:} {}
#cond {($abilities:*)} {The easy way to get this list of abilities into a variable is to capture them all at once and then replace the spaces with pipe characters: #addkey IDItem Abilities %replace($abilities," ","|")}
At this point, you'll want to enable a class that contains patterns for all the optional lines you can have. Then, finally, you'll want some line that terminates your item (a blank line or your prompt, usually) at which you turn everything off and store the item in the database.
Oh, the regex for the money needs improving; it won't match all the time. |
|
|
|
|
|
|
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
|
|