Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Problems with list parsing
Problems with list parsing
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tiopon
USA (71 posts) Bio
|
Date
| Thu 06 Aug 2009 12:15 AM (UTC) Amended on Thu 06 Aug 2009 12:25 AM (UTC) by Nick Gammon
|
Message
| I'm using the following trigger to parse my inventory...
<triggers>
<trigger
keep_evaluating="y"
match="^([a-z#_\' -:]*) ([a-zA-Z\ .]*)$"
name="skill_line"
regexp="y"
send_to="12"
sequence="50"
>
<send>local SkillName = string.gsub("%1", ":%s+$", "")
local SubName = string.gsub(SkillName, "[ '#-]", "_")
local SkillLevel = string.gsub("%2", "[.]", "")
skill_table[SubName] = skill_table[SubName] or {}
skill_table[SubName].name = SkillName
skill_table[SubName].level = SkillLevel
skill_table[SubName].count = GetVariable (SubName .. "_skill")
</send>
</trigger>
</triggers>
The list looks like one of the following...
delior's_pocket_dimension: Proficient.
language#southern: Not Very Good.
stone working: Poor.
Specifically, the issue is with the delior's_pocket_dimension skill... this one, because it only has a single space, fails to remove the :, unlike the others... the normal ones parse like this...
Quote: delior's_pocket_dimension: nil Proficient
language#southern 68 Not Very Good
stone working 30 Poor
As you can see, delior's_pocket_dimension fails, including having a : remaining in its name.
Basically, I'm trying to see if there's a better way to have it parse the names, removing all ending spaces in the skill names. The main issue is that spaces may be found in the skill names, as well as their descriptive names, and I haven't found a better way to get results. This works perfectly except for with this one skill. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 06 Aug 2009 12:27 AM (UTC) |
Message
| Your regular expression in the trigger looks for a space between wildcard 1 and wildcard 2, so the space after the colon is not returned as part of wildcard 1.
A simple fix would be to change the Lua regexp to:
local SkillName = string.gsub("%1", ":%s*$", "")
Now that looks for zero or more spaces, rather than 1 or more spaces. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Tiopon
USA (71 posts) Bio
|
Date
| Reply #2 on Thu 06 Aug 2009 12:45 AM (UTC) |
Message
| Okay, so set it to this, which is what I believe you suggested...
<triggers>
<trigger
keep_evaluating="y"
match="^([a-z#_\' -:]*) ([a-zA-Z\ .]*)$"
name="skill_line"
regexp="y"
send_to="12"
sequence="50"
>
<send>local SkillName = string.gsub("%1", ":%s*$", "")
local SubName = string.gsub(SkillName, "[ '#-]", "_")
local SkillLevel = string.gsub("%2", "[.]", "")
skill_table[SubName] = skill_table[SubName] or {}
skill_table[SubName].name = SkillName
skill_table[SubName].level = SkillLevel
skill_table[SubName].count = GetVariable (SubName .. "_skill")
</send>
</trigger>
</triggers>
Still parses the same though... | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Thu 06 Aug 2009 01:00 AM (UTC) |
Message
| I pasted in your trigger, enabled it, and tested it like this:
delior's_pocket_dimension: Proficient.
language#southern: Not Very Good.
stone working: Poor.
require "tprint"; tprint (skill_table)
"delior_s_pocket_dimension":
"level"="Proficient"
"name"="delior's_pocket_dimension"
"language_southern":
"level"="Not Very Good"
"name"="language#southern"
"stone_working":
"level"="Poor"
"name"="stone working"
It seems to have worked. The final colon is added by tprint. The name inside the quotes has the colon removed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Tiopon
USA (71 posts) Bio
|
Date
| Reply #4 on Thu 06 Aug 2009 01:43 AM (UTC) |
Message
| Wiped my list completely and started over, and it worked properly. Thanks! You always have a great answer. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,721 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top