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
➜ Using script to practice/research skills
Using script to practice/research skills
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Brendolino
(19 posts) Bio
|
Date
| Wed 12 Dec 2007 01:29 AM (UTC) Amended on Wed 12 Dec 2007 07:25 PM (UTC) by Nick Gammon
|
Message
| I want to write a Lua script to take anything on my practice list under a certain percentage, and research it. I have triggers to keep the research continuing until it maxes, at which point I'll use the return message to view my prac list again. Here is a sample of the practice list:
construction 0% data 15% decrypt_file 86%
there are more spaces between skills, but I had to knock some out to fit them in the messagebox. Basically, its a 3 wide mostly-right-justified list. Should I use variables and wildcards, or just hardcode every skill into the function? Examples would be excellent, I'm extremely novice at this.
| Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Wed 12 Dec 2007 01:21 PM (UTC) |
Message
| If you are just trying to make a trigger to pull out the data, you mostly just need something like this:
"%s*(w+(?:\s\w+)+)(%d+\%)(%s*(w+(?:\s\w+)+)(%d+\%)){0,2}"
Then just test the wildcards.. the odd ones will be the skill names, the even ones will be the rating of the skill preceding it. If the last few are nil, then you can just skip over them.
Somewhere in the forums, there is a good example of someone making up a set of values out of a large list of items grouped into three columns. It was for item trading, but it should work the same. Unfortunately, I can't seem to find it and I have to actually start work now. I'll check more on my lunch break. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Brendolino
(19 posts) Bio
|
Date
| Reply #2 on Wed 12 Dec 2007 02:00 PM (UTC) |
Message
| Alright, that was a bit too huge for me to diagnose myself,
but I created a trigger with that whole string as the <trigger:>, and a simple 'say %0' as the <send:> and nothing happened. I'm not sure if it makes a difference or not, but the message board's parsing changed my example. Here is a better, spelled out example.
<skill name><1 space><100%> <--the 1 space is dependant on the percentage in that skill. For a skill with 0%, it will be 3 spaces between the skill name and the first number of the percent: <skill name><3 spaces><0%>.
Now I'm absolutely new to Lua, and regexp, so I can't even begin to diagnose the problem with the regexp example you gave. I basically want to grab the first <skillname> for anything with a percentage of X% or less, anywhere on a line, and send a trigger to research it, or use a Lua script to send "research <skillname>". | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #3 on Wed 12 Dec 2007 07:40 PM (UTC) |
Message
| I amended your first post to put the [code] tag into it, to preserve spacing.
Regular expressions can be tricky to look at a complete example, but if you build them up yourself they can make more sense. See http://www.mushclient.com/regexp
In your case it sounds like you want a word with possibly underscores in it, so I would start with:
That is, one or more of A-Z or underscore.
Then it sounds like you have at least one space, so let's add that:
Then you have 3 digits or spaces (that is, leading spaces). So one approach would be:
That looks for exactly 3 digits-or-spaces. Admittedly it would allow for imbedded spaces, but it is probably close enough.
Now add the percent:
Now we need two groups (which are things in round brackets), one for the skill name and one for the percentage:
([A-Za-z_]+)\s([0-9 ]{3})\%
That gives us the first one. I don't know how many spaces between groups (it seemed to be 6), you can add that in, and a simple copy and paste would handle 3 of them in one line:
([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%
Put in ^ for start of line and $ for end of line and you are done:
^([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%\s{6}([A-Za-z_]+)\s([0-9 ]{3})\%$
In this example, %1 in the trigger is the first skill name, and %2 is the first percentage.
The finished trigger could look like this:
<triggers>
<trigger
enabled="y"
match="^([A-Za-z_]+)\s([0-9 ]{3})\% {6}([A-Za-z_]+)\s([0-9 ]{3})\% {6}([A-Za-z_]+)\s([0-9 ]{3})\%$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
MIN_AMOUNT = 60
if %2 < MIN_AMOUNT then
Send ("research %1")
end -- if
if %4 < MIN_AMOUNT then
Send ("research %3")
end -- if
if %6 < MIN_AMOUNT then
Send ("research %5")
end -- if
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Brendolino
(19 posts) Bio
|
Date
| Reply #4 on Wed 12 Dec 2007 11:18 PM (UTC) |
Message
| Alright, in the event that the spaces between skills aren't necessarily 6, can I do: \s{[0-20 ]} instead of \s{6} ?
Anyhow, if examples are needed:
www.geocities.com/dalograk/example.html
That really gives the MUD away, though. >.> | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #5 on Wed 12 Dec 2007 11:27 PM (UTC) |
Message
| It would be \s{1,8} to be 1 to 8 spaces. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Brendolino
(19 posts) Bio
|
Date
| Reply #6 on Wed 12 Dec 2007 11:32 PM (UTC) |
Message
| Still not working for me. I'm probably jumping too far ahead of myself trying out a project like this before getting much regexp, or coding in general, experience. Thanks for the help, I'll just keep at it until I can figure it out. | 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.
22,989 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top