Help with Table - Regex

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Help with Table - Regex

Post by Deshanti »

Hey guys, I've been trying to reach the IRC help channel for the past 2 days, but apparently I come at odd times and people can't assist me. Anyhow what I wish to accomplish is to write an Autoresearch script. On the mud I play at, we are able to use a skill that is called research, which increases the percentage of some skills by 10-15 or something like that.

My aim is;
1- To capture the date when I type practice.
2- Turn this data into a table.
a) Write a regex that can accomplish this.
b) Write the lua code to turn the data regex captures, into a table.
3- Then add bunch of triggers to make the research automatic.
4- (Miscellenous) Colour the code within which the practice list will appear.


So far I completed 1. I'm stuck on the second goal. I'll give a brief understanding of the system;
There are 11 classes; Combat, Piloting, Engineering, Diplomacy, Leadership, Slicer, Smuggling, Espionage, Medical, Science and Bounty Hunting.

When we type practice, it shows all the skills we have the necessary level of in every class. When we type practice <class name>, it only shows the skills list of that particular class we have unlocked.

This is the full practice list;
http://pastebin.com/FUvBAYeC

This is an example for the combat practice list;
http://pastebin.com/wBKkSWyE

--------

I have achieved the first goal by starting to capture when it says ---skills---, and ending the data capture when it says ----feats----.

I spent 2-3 days trying to write the regex needed to capture the data I wanted. The challenge was that, as you can see, on every line 3 skills come up with. So I needed to write a regex that'll capture all three skills per line. Then the advanced challenges were including two worded skills in regex and finally including space combat 1.

Then the challenge was that whenever a line had less than 3 skills, (Usually in the end). I managed to overcome that, but I have failed to apply this into the list code.

Here is my regex code;
\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%|\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%|\s*(\w+|\w+[ -]\w+|\w+ \w+ \d)\s*\d*%

Here is my table code;
table.insert(my_skills, matches [2])
table.insert(my_skills, matches [3])

My ultimate goal is to create a table that captures each skill with its name and the percentage. Then skills with less than 80% will be added into the Autoresearch pool, where the script will research them until they are above 80%.

However while fiddling with the regex code, I think I got really stupid. Because currently the code I wrote only acquires the name of the skills. Which is useless without its percentage.

I've been using Mudlet for a while now, I'm trying to better myself so if you guys could guide me, I'd really appreciate it.

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Help with Table - Regex

Post by Lezard »

Hiya! An easy way to do it would be to just set the fire length of the trigger to 40 lines and then capture each skill and percentage with another trigger inside. Do you understand this or would you like an example?

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Re: Help with Table - Regex

Post by Deshanti »

Yeah that's the method I used. I captured the data, then added a different trigger ITEM to use the regex to define the captured data and turn it into a list.

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Re: Help with Table - Regex

Post by Deshanti »

My problem was never that. I just need to be able to write a proper Regex to capture each skill name along with its percentage and then find a way to put them into a table which I can use to recall said skills from.

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Help with Table - Regex

Post by Lezard »

Hmm.. I would have to play around with it a bit. I believe this regex should do.
Code: [show] | [select all] lua
Text: advanced electronics  97%

regex: ([a-z ]+)\s+(\d+)\%

table.insert(my_skills, string.trim(matches[2]))
table.insert(my_skills, tonumber(matches[3]))
another way to do this would be to make a table inside of my_skills for each research and percentage. For example:
Code: [show] | [select all] lua
my_skills = {
 { research = "advancedelectronics",    percentage = 0 },
 { research = "construction",           percentage = 0 },
 -- and so forth --
}
and then within the regex trigger you would do something like:
Code: [show] | [select all] lua
for _, v in ipairs(my_skills) do
 if v.research == string.trim(matches[2]) then
  v.percentage = tonumber(matches[3])
  if v.percentage < 80 then
   table.insert(my_skills.researchthese, v.research)
  end
 end
end
Again, this is just to give you an example of how it might be done. My coding isn't that advanced, so i'm sure i've made a few errors in this. I couldn't tell you how to research those up to 80 unless I had more information on how to do it. If you have any questions just send me a pm and i can give you my msn.

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Re: Help with Table - Regex

Post by Deshanti »

I don't quite understand this method though. The regex will probably cover only the first skill on each line and for instance space combat 1 can not be covered by it. Also if I am to create the research table myself manually, then we'd have a problem. Because not everyone will be able to unlock all the skills, the skills are listed in alphabetical order. So someone lets say with 149 combat level, won't get the 150 combat level flurry. If I make the table manually and say, advanced electronics is the first skill, then odds are all skills will get mixed together.

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Help with Table - Regex

Post by Lezard »

in the trigger, check "match all", and that should fix the "only matching the first skill on each line" problem.
as for capturing space combat 1, just change the regex to: ([a-z1-9 ]+)\s+(\d+)\%

as for everything you said after that, It wouldn't matter what skills they had, it would capture it. I think the only problem would be if they had more or less skill than you, it would capture before or after the ----feats---- line..

You could remedy this by creating a few triggers in a folder. The first one, ---skills--- will enableTrigger("captureResearch") or whatever the name is.

then trigger ---feats--- to disableTrigger("captureResearch")

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Re: Help with Table - Regex

Post by Deshanti »

Okay with Vadi's and Lezard's assistance, I was able to complete Goal 2. Now I need to be able to use this table and manipulate it.

How to do it?
I need to be able to process this table based on the percentage level. If they are less than 80% I need to add them to a new table which will be my research queue table. Then I will be writing a trigger that researches these skills to the point where I cannot research them anymore and thus remove them from the queue.

Problem is, I'm stuck in the very beginning. I'm not entirely sure how I could write a function or a code that'd access every single skill's percentage and move those that has less than 80 value in their percentage to a new table.

Any suggestions?

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Help with Table - Regex

Post by chris »

Code: [show] | [select all] lua
function moveskills()
 table2 = {}
 for i,v in pairs(table1) do
  if (v<80) then
   table.insert(newtable2,v)
  end
end

Deshanti
Posts: 10
Joined: Sat Feb 25, 2012 10:29 am

Re: Help with Table - Regex

Post by Deshanti »

Thank you Chris, it did help. However when I started using the script, we had a problem. Vadi's suggested code doesn't seem to be capturing every skill and percentage. The regex does cover all of the skills and percentages when I click on match all, yet the same is not the case when it comes to pulling them to the table.

The code only picks the first skill on each line.

An example of the list;

aim 45% bash 0% berserk 0%
blastdoor 60% disarm 90% dodge 0%
dual wield 90% enhanced damage 96% flurry 0%
gouge 90% grenades 0% grip 0%
hitall 93% kick 90% mines 0%
mount 60% rescue 98% scan 100%
second attack 91% snipe 91% throw 20%
---------------------------------Weapons-----------------------------------
advanced blaster 90% advanced bowcaster 0% advanced forcepike 0%
advanced vibroblade 60% blaster mastery 91% blasters 99%
bowcaster mastery 90% bowcasters 0% force pikes 0%
forcepike mastery 90% unarmed combat 0% vibro-blades 20%

The regex:
([a-z1-9-_ ]+)\s+(\d+)\%

The code:
my_skills[string.trim(matches[2])] = tonumber(matches[3])

Post Reply