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
➜ General
➜ Wildcards, Functions & Lua Tables
Wildcards, Functions & Lua Tables
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Mccane
(28 posts) Bio
|
Date
| Tue 06 May 2008 11:32 AM (UTC) Amended on Tue 06 May 2008 11:48 AM (UTC) by Mccane
|
Message
| Okay, on the MUD I am playing you have a set of skills. For example, you might see something like
Alchemy: 10% Engineering: 5%
Herbalism: 8% Tailoring: 32%
and on and on, up to about 60 skills. I would like to store each of the skills with their respective percentage points into Lua tables, upon which my script will 'rank' each of these skills into prioritized lists of skills I need to improve (i.e. it will find skills below x% and add it to a list, then when it has iterated throughout the entire table will print the list to me, in order from the lowest to highest.)
I wrote this trigger to capture each skill:
<triggers>
<trigger
enabled="y"
match="(.*?) (.*?[0-9.])\%"
name="skill"
regexp="y"
script="skill_function"
sequence="100"
>
</trigger>
</triggers>
Here is the skill_function:
function skill_function (name, line, wildcards)
local function skill (m, t)
table.insert (skills, m)
end
local re = rex.new (GetTriggerInfo (name, 1))
re:gmatch (line, skill)
end
This will insert every skill to the table nicely, but I'm not quite sure where to proceed from here. I'm fairly sure my method of storing the skills is incorrect for what I want to do. How can I take 'm', what the trigger matched on, and break that down into both the skill name and its percentage? I tried using named expressions and then calling these in the function. I changed my match to:
(?P<skill>.*?)\: (?P<level>.*?[0-9.])\%
and then tried accessing these in the function, but it then would no longer store all the skills. I changed the function to look like this:
skills [wildcards.skill] = wildcards.level
This works somewhat, but it only stores the skills in the first column. Given the above example of skills, I would get something like this:
/table.foreach (skills, print)
Alchemy 10
Herbalism 8
Is there some easier way to go about this? | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Tue 06 May 2008 06:30 PM (UTC) |
Message
| Allow the regex trigger to continue matching on the line... or allow a regex with potentially multiple skills on each line grabbing them, then test for existence before adding a new item to the table.
make match:
(?P<skill>.*?)\: (?P<level>.*?[0-9.])\%(?:\s+(?P<skill2>.*?)\: (?P<level2>.*?[0-9.])\%)?
Then have this code:
skills [wildcards.skill] = wildcards.level
if wildcards.skill2 then
skills [wildcards.skill2] = wildcards.level2
end
|
It is much easier to fight for one's ideals than to live up to them. | 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.
12,146 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top