|
Scirkhan Apprentice
Joined: 14 Sep 2007 Posts: 167 Location: aztx
|
Posted: Wed Nov 14, 2012 5:07 pm
How to better capture a pattern? |
I'm using 3 reParse triggers. How can I do this better? I don't really remember anything about this. Thanks..
I have no idea...
Quote: |
Cause Light Wounds [95/95] Cause Serious Wounds [95/95]
Control Weather [58/95] Create Food [00/95] Create Water [00/95]
|
Code: |
#TRIGGER "Skills_practice_capture" {^%w%s*~[} {} "" {disable}
#COND {^(%w)(*)%s~[(%d)/%d~]{ |}$} {} {reparse|disable}
#COND {^(%w)(*)%s~[(%d)/%d~] (%w)(*)%s~[(%d)/%d~]{ |}$} {} {reparse|disable}
#COND {^(%w)(*)%s~[(%d)/%d~] (%w)(*)%s~[(%d)/%d~] (%w)(*)%s~[(%d)/%d~]$} {} {reparse|disable} |
Either people want me to keep things relevant, or put all the information up. hah... |
|
Last edited by Scirkhan on Wed Nov 14, 2012 6:47 pm; edited 2 times in total |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Wed Nov 14, 2012 5:14 pm |
that looks so ugly without the ; shifted into carriage returns... hard to read
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Scirkhan Apprentice
Joined: 14 Sep 2007 Posts: 167 Location: aztx
|
Posted: Wed Nov 14, 2012 5:57 pm |
how do I.. shift the ; into carriage returns? Right.. I guess it's just impossible to read scripts yet we can make them.
I guess I should go grab myself an IDE or something. But I don't have any nerd-mighty friends to tell me about this stuff. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Wed Nov 14, 2012 9:34 pm |
Its actually an option in the editor itself, in one of the menues... reformat script or somesuch
No one said it was impossible, but certain things do make people more willing to attempt it.
And no one said you had to remove all the relevant data either, just the way you had it displayed as a run-on sentence of code, it was hard to see what you were doing. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Wed Nov 14, 2012 9:42 pm |
Hmm... have you tried using a
#SUB {}
to remove the section of the pattern you just matched on before reparsing?
Then you might not need more than one state...
also..
#TR {^([%w%s])~[(%d)/%d~]}
is a more concise pattern for the bit you actually want to match, i think
or, on a totally different page, you could use something like
parts=%replace(%line, "] ", "]|")
then #FORALL @parts through a %match to do all your stuff |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Scirkhan Apprentice
Joined: 14 Sep 2007 Posts: 167 Location: aztx
|
Posted: Thu Nov 15, 2012 2:56 pm |
Hey thank you shalimar. I'll try those. sometimes spells are more than one word long.
Just trying to make it more efficient. Is there a way regex can do this? %w3 or something.
Actually.. I would like to know how to find out what is more efficient.
one db, or 5 string lists? What matches faster, or with less cycles, etc
^[\w\s]{3,30}\s\s
edit:
efficient I hope.
Quote: |
parts=@parts%replace( %line, "]", "]|")
then when all done, parts=%dups(@parts) |
or
Quote: |
#additem parts {%replace( %line, "]", "]|")} |
or (line by line)
Quote: |
parts=%replace( %line, "]", "]|")
#forall |
Those are the sort of efficiency questions I have.
Is there anyway I can use match without variables? or delete variables without unvar?
or is that like #trigger {@Name=1} {}
Hmm. It seems I can't %trim(%line) |
|
Last edited by Scirkhan on Thu Nov 15, 2012 9:52 pm; edited 4 times in total |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Thu Nov 15, 2012 8:14 pm |
[%w%s] = any amount of white space and words
It could be done in regex (and in fact is converted to regex behind the scenes) but i was never good with raw regex
Code: |
parts=%replace(%line, "] ", "]|")
^ |
my example has a space after the closing square bracket, to give it a boundary that wont result in a blank member in the @parts variable
As to the variables... if you upgrade to CMUD, it makes use of local variables which would be thrown out when the trigger finishes.
Staying with zMuUD though..
you could use the #VAR command to assign them a class at creation, then just delete the class with all your temporary variables
or just reuse the same temporary variables in any script that needs them, since script redefines them, a few variables in memory should not create a noticeable impact on system performance
and i want to say separate string lists are faster in zMUD, with no discernible differance in CMUD
and yes, you can make expression triggers |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Scirkhan Apprentice
Joined: 14 Sep 2007 Posts: 167 Location: aztx
|
Posted: Thu Nov 15, 2012 8:20 pm |
Yes, I was aware of the space. I just realized why it *wasn't* trimming how I thought it should. my bad.
Thank you for the class idea for temporary variables.
I could probably use subregex to remove the blank space at start of line, but I think I can encapsulate just another %replace %replace..
Ah, I got it to work like this, with %subregex and \s*. The dot is because I can't get match to work with [ or ~[:
Code: |
test/parts=@test/parts%replace( %subregex( %line, "\]\s*", "]|"), "[", ".") |
Oh, and I think I do remember something about string lists being considerably faster than DBs.
Is there a decent way to test this? Just use %time()? I liked the db because it's just one list.
I suppose I can make a string list with a delimiter. [didn't do this. Not sure how I would find what I want from it.]
Heh, the class-path specification, @test/spell, in my #forall loop and #add %if added 20ms delay. That is surprising.
So I removed that. I have it at 180ms.
zMuD does not like %subregex %replace it seems.. everytime I try to import the script, it messes up on that line.
I put a tilde in front of every % " and @ for that line in the file. Seems to fix it..
Ok.. I got around that problem. Not sure what was wrong. |
|
Last edited by Scirkhan on Fri Nov 16, 2012 1:54 pm; edited 2 times in total |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Fri Nov 16, 2012 3:10 am |
#VAR parts {%replace(blah blah)} _nodef test
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Scirkhan Apprentice
Joined: 14 Sep 2007 Posts: 167 Location: aztx
|
Posted: Fri Nov 16, 2012 3:13 am |
Yeah.. I don't know what was wrong.. it was very strange.
As long as I import this new one and don't copy/paste it.
It doesn't take too long.. I guess I'm done. Yeah. Thanks shalimar!
Code: |
#CLASS {Skills}
#ALIAS help {~help %-1
#if (%-1 = "classes") {#class Skills
#state skills_cond 0
#T+ "skills_cond"}}
#ALIAS prac {~prac %-1
#if (%-1 = "") {#class Skills
#T+ "Skills_practice_start"}}
#VAR Divisor {9}
#VAR WarriorBonus {12|0|0}
#VAR ThiefBonus {9|0|12}
#VAR DruidBonus {6|6|3}
#VAR ClericBonus {0|6|0}
#VAR MageBonus {0|6|0}
#VAR class {}
#VAR classSkills {}
#VAR skillsLine {}
#VAR practiceSkills {}
#VAR practiceSkill {}
#VAR skill_percent {00}
#VAR H {0}
#VAR M {0}
#VAR V {0}
#TRIGGER "Skills_blankline" {$} {#if (@class = "Druid") {#state skills_cond 0
#t- "skills_cond"} {#STATE skills_cond 1}
#t- "Skills_blankline"} "" {notrig|disable}
#TRIGGER "skills_cond" {^CLASSES$} {#var Skills/class {}
#var Skills/classSkills {}
#var Skills/SkillsLine {}} "" {disable}
#COND {^({Warrior|Cleric|Mage|Druid|Thief})-$} {#var Skills/class {%1}
#t+ "Skills_blankline"
#state skills_cond 2} {disable}
#COND {^(%w)} {#var Skills/skillsLine {%replace( %replace( %lower( %line), ", ", |), ",", "")}
#DELI Skills/skillsLine %null
#pri {#FORALL @Skills/skillsLine {#addkey classSkills {%i} {@Skills/class}}}} {manual|disable}
#REGEX "Skills_practice_capture" {^\w[\w\s]+\s[\s\[]} {#pri {practiceSkills=@practiceSkills%replace( %subregex( %lower( %line), "\]\s*", "]|"), "[", ".")}} "" {notrig|disable}
#TRIGGER "Skills_practice_end" {^You have (%n) practice sessions remaining.$} {#class Skills
#t- "Skills_practice_end"
#t- "Skills_practice_capture"
practiceSkills=%dups( @practiceSkills)
#deli practiceSkills %null
#var practiceSkill {}
#var skill_percent {0}
#var H 0
#var M 0
#var V 0
#forall @practiceSkills {#noop %match( %i, "(*)%s.(%d)", practiceSkill, skill_percent)
#var practiceSkill {%trim( @practiceSkill)}
#add H {%if( @skill_percent>=90, %item( @{%db( @classSkills, @practiceSkill)Bonus}, 1))%if( @skill_percent<90 AND @skill_percent>=50, %eval( %item( @{%db( @classSkills, @practiceSkill)Bonus}, 1)/2))}
#add M {%if( @skill_percent>=90, %item( @{%db( @classSkills, @practiceSkill)Bonus}, 2))%if( @skill_percent<90 AND @skill_percent>=50, %eval( %item( @{%db( @classSkills, @practiceSkill)Bonus}, 2)/2))}
#add V {%if( @skill_percent>=90, %item( @{%db( @classSkills, @practiceSkill)Bonus}, 3))%if( @skill_percent<90 AND @skill_percent>=50, %eval( %item( @{%db( @classSkills, @practiceSkill)Bonus}, 3)/2))}}
#SUB {You have %ansi(high,yellow)%1%ansi(green) practice sessions remaining.%ansi(high,red) +%eval( @H/@Divisor)hp%ansi(high,blue) +%eval( @M/@Divisor)mana%ansi(high,green) +%eval( @V/@Divisor)move}
#class 0} "" {disable}
#TRIGGER "Skills_practice_start" {You can learn the following skills and spells:$} {#class Skills
#t- "Skills_practice_start"
#T+ "Skills_practice_capture"
#T+ "Skills_practice_end"
#var Skills/practiceSkills {}
#var Skills/H {0}
#var Skills/M {0}
#var Skills/V {0}} "" {disable}
#CLASS 0 |
I didn't try the #sub suggestion, but it seems like it would be pretty good, creative too. The #forall approach was really key here. I never was good with #forall.
So, thanks again. |
|
|
|
|
|
|
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
|
|