Capture Table - Flawed

albulak
Posts: 9
Joined: Tue Jul 25, 2017 11:00 am

Capture Table - Flawed

Post by albulak »

Alright guys I will show you the scripts, aliases and triggers I have for a research function. Basically in our mud every skill has a percentage that they can be researched up to. Right now my code helps me capture all the skills on research and their percentage values, then start researching them.

Scripts:
Code: [show] | [select all] lua
function removefromlist()
table.remove(researchthese, 1)
  research.skill = researchthese[1]
  cecho("\n<yellow>Skill changed to: "..research.skill)
  send("research "..research.skill)
end
-------
Code: [show] | [select all] lua
function moveskills()
 researchthese = {}
 for i,v in pairs(mySkills) do
  if (v<80) then
   table.insert(researchthese,i)
  end
end
end
-------------------------------------------------------------
Triggers:

You study for hours on end, but fail to gather any knowledge. | Exact match
Code: [show] | [select all] lua
if researching then
 cecho("\n<yellow>Study harder, bitch!")
send("research "..research.skill)
end
-------
You finish your studies and feel much more skilled. | Exact match
Code: [show] | [select all] lua
research.percent = research.percent + 15
if researching then
 if research.percent < 81 then
send("research "..research.skill)
cecho("\n<yellow>Current percentage: "..research.percent.."%")
else
 table.remove(researchthese, 1)
research.skill = researchthese[1]
research.percent = research.percent
cecho("\n<yellow>Skill changed to: "..research.skill)
send("research "..research.skill)
 end
end
--------
You can't learn any more about that from books! | Exact match
Code: [show] | [select all] lua
if researching then
 if research.percent >= 80 then
 cecho("\n<yellow>Percent is higher than 80.")
  table.remove(researchthese, 1)
 research.skill = researchthese[1]
 cecho("\n<yellow>Skill changed to: "..research.skill)
  send("research "..research.skill)
 else
  cecho("\n<red>Something is wrong here.. You are below 80 percent?")
 end
end
--------
I got various syntaxes refusing to research skills saying they cannot be researched. Or that I am done researching them so what it does is;

tempTimer( 2, [[removefromlist()]] )
--------
The Skills capture parser:
---------------------------------Skills----------------------------------- | exact match
mySkills = {}
--------
^\{Tone:
^\[HP: | Both perl regex (To end the capture I think)
setTriggerStayOpen("skills", 0)
display(mySkills)
--------
\s*([a-zA-z\- ]+\d+)% | Perl regex (No output just the folder name and this trigger)
--------
([a-zA-z \-]+)(\d+) | Perl regex
Code: [show] | [select all] lua
if string.trim(matches[2]) ~= "" then
mySkills[string.trim(matches[2])] = tonumber(matches[3])
end
--------
Aliases:

I have two aliases, one is called msnow.
Output: moveskills()

-----

The second alias is ^tr (\w+)$
Code: [show] | [select all] lua
if matches[2] == "on" then
 research = {}
 research.skill = researchthese[1]
 research.percent = tonumber(mySkills[researchthese[1]])
 researching = true
 send("research "..research.skill)
 cecho("\n<green>Research Mode - Enabled")
elseif matches[2] == "off" then
 researching = false
 cecho("\n<red>Research Mode - Disabled")
end
------------------------------------------------------------------------------------------------

I will paste you an example of practice window's output from mud and my prompt to help you understand. (Also the research capture displaying the table)

------------------------------------Skills ------------------------------------
dock 0% fly 0% navigation 100%
ship systems 100% small spacecraft 100% space combat 1 0%
tractor beams 0% weapon systems 20%
------------------------------------ Feats ------------------------------------
To see a shorter practice list, type PRACTICE <class name>.

[HP: 3273/3273] [OOC: 6] Time: [ day] Tone: [none] [Movement: 2770/2770] [Near: ] [Mana: 0/0]
[Ambience: average]{
["weapon systems"] = 20,
["tractor beams"] = 0,
dock = 0,
fly = 0,
["ship systems"] = 100,
["small spacecraft"] = 100,
navigation = 100
}

You finish your studies and feel much more skilled.

----------------------------------------------------------------------------------------

I have 3 problems as it stands:
1- When I trigger my research code via;
- practice
- msnow
- tr on
The script will capture the numbers and then take the first item on the list and then research it all the way above 80 percentage value. Once that one is above 80, it will move to the next skill, ---it will research it only once---. Once the final skill is researched it will stop the code.

I would like it so that I am able to research every skill to its potential. Not the first to its potential and then rest only once.

2- My capture does not capture skills named "space combat 1" "space combat 2" etc. It's not a huge problem, I simply was wondering if it can easily be fixed, if not no huge deal.

3- This is within number 1 too. As it stands the code will move to the next skill, but refuse to take its research value. Is there a way to force the code to go back to the table and capture whatever number its value is?

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Capture Table - Flawed

Post by Jor'Mox »

So, to get some of the low hanging fruit here, your trigger to get the skill and percentage, that isn't getting skills that have numbers in them, should be changed to this: \s*([a-zA-z\- \d]+) (\d+)%
With that, you should be able to drop the nested trigger, and it should match skills with or without numbers in their names.

Secondly, I notice that you aren't properly reseting your skill percentage when you switch skills to research, which is why everything after the first is only researched once. A lot of your code looks like it is doing similar things in different locations, which is going to make this a bit harder to keep track of, and to fix in all instances, but every time you switch skills, you also need to switch percentages. I would recommend making simple function that performs this task for you. Using the variables you already have setup, I think the function could look something like this:
Code: [show] | [select all] lua
function nextSkill()
   research.skill = table.remove(researchthese,1)
   if research.skill then
      research.percentage = mySkills[research.skill]
      cecho("\n<yellow>Skill changed to: " .. research.skill .. "<reset>")
      send("research " .. research.skill)
   else
      cecho("\n<red>No more skills to research!<reset>")
   end
end
Then, every time you need to switch to the next skill to research, you would just call the nextSkill function. Note that it is properly getting the skill percentage from the mySkills table, which was only happening when you were using your tr alias. Also, note that this function will work just fine for starting research on the first skill in the list, so you don't need a separate call to get things started, just call nextSkill, and it will take care of it.

albulak
Posts: 9
Joined: Tue Jul 25, 2017 11:00 am

Re: Capture Table - Flawed

Post by albulak »

Jor'Mox thank you VERY MUCH! For helping out. I tried the capture perl regex you gave, but it did not work.

This is the version with the old one.
------------------------------------Skills ------------------------------------
dock 0% fly 0% navigation 100%
ship systems 100% small spacecraft 100% space combat 1 0%
tractor beams 0% weapon systems 20%
------------------------------------ Feats ------------------------------------
To see a shorter practice list, type PRACTICE <class name>.
[HP: 3273/3273] [OOC: 6] Time: [ day] Tone: [none] [Movement: 2770/2770] [Near: ] [Mana: 0/0]
[Ambience: average]{
["weapon systems"] = 20,
["tractor beams"] = 0,
dock = 0,
fly = 0,
["ship systems"] = 100,
["small spacecraft"] = 100,
navigation = 100
}

This is the version with yours.
------------------------------------Skills ------------------------------------
dock 0% fly 0% navigation 100%
ship systems 100% small spacecraft 100% space combat 1 0%
tractor beams 0% weapon systems 20%
------------------------------------ Feats ------------------------------------
To see a shorter practice list, type PRACTICE <class name>.

[HP: 3273/3273] [OOC: 6] Time: [ day] Tone: [none] [Movement: 2770/2770] [Near: ] [Mana: 0/0]
[Ambience: average]{
["space combat"] = 1

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Capture Table - Flawed

Post by Jor'Mox »

Well then I would just use the regex I suggested for the nested trigger instead, and adjust the regex of the higher level trigger to allow for numbers in the word, like this: \s*([a-zA-z\- \d]+%)
The one really important thing is to keep the % in what is going to the lower level triggers, so it can distinguish between a number that is part of the skill name, and the number that is the skill percentage.

Edit:
For simplicity sake, you can probably shorten your regex a bit, by using the \w abbreviation.
So, your higher level trigger could be: \s*([\w\- ]+%)
And the lower level trigger could be: ([\w\- ]+) (\d+)%

albulak
Posts: 9
Joined: Tue Jul 25, 2017 11:00 am

Re: Capture Table - Flawed

Post by albulak »

New update:
I used the function you gave me and replaced my triggers so they ran with it. The result was;
Well it is the same, researched the first skill to maximum potential and then the rest to 15.

Also I'm not really good with regex. But what I tried was I replaced the nested trigger with your regex, and kept the other one for the subfile.
It again showed:
]{
["space combat"] = 1
}

Edit:
Perl Regex you gave last time around worked brilliantly. The upper one showed space combat = 1 but when I added the sub perl regex you gave, it showed all of the skills. Thank you :)

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Capture Table - Flawed

Post by Jor'Mox »

Okay, so I made a test trigger on the game I play (with a fairly similar layout for how it shows skills), and it worked pretty well with this pattern: ([\w\s]+) (\d+)% AND with the "match all" checkbox checked. For testing out trigger, I also find using the "highlight" checkbox to be handy, as you can see exactly what is getting captured and what isn't.

Edit: never mind then.

SO, at this point, you are now capturing all your skills properly, but you aren't researching any but the first correctly, right?

albulak
Posts: 9
Joined: Tue Jul 25, 2017 11:00 am

Re: Capture Table - Flawed

Post by albulak »

Aye that's right. The first one is researched fully, the rest are researched only once.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Capture Table - Flawed

Post by Jor'Mox »

Okay, so can you repost the code for your three triggers that get the results of your research, now that you have changed them?

albulak
Posts: 9
Joined: Tue Jul 25, 2017 11:00 am

Re: Capture Table - Flawed

Post by albulak »

You study for hours on end, but fail to gather any knowledge. | Exact match
[codebox=]if researching then
cecho("\n<yellow>Study harder, bitch!")
send("research "..research.skill)
end

--send ("research ".. rsc)
[/codebox]

You finish your studies and feel much more skilled. | Exact match
[codebox=]research.percent = research.percent + 15
if researching then
if research.percent < 81 then
send("research "..research.skill)
cecho("\n<yellow>Current percentage: "..research.percent.."%")
else
tempTimer( 2, [[nextSkill()]] )
end
end[/codebox]

You can't learn any more about that from books! | Exact match
[codebox=]if researching then
if research.percent >= 80 then
tempTimer( 2, [[nextSkill()]] )
cecho("\n<yellow>Percent is higher than 80.")
else
cecho("\n<red>Something is wrong here.. You are below 80 percent?")
end
end[/codebox]

You can't learn smuggling skills from a book! | Exact match
tempTimer( 2, [[nextSkill()]] )

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Capture Table - Flawed

Post by Jor'Mox »

So, I see the problem. I used "research.percentage" in the nextSkill function, and you are using "research.percent" in your triggers. So just fix my typo in the nextSkill function, and it should probably start working.

Post Reply