Alright. So I've been away for a while (going on a year), and I'm trying to get back into Mudlet coding so I can work at my GUI once again! Unfortunately, in bashing my brain meats around I still can't get past one issue that plagued me even back then. That issue being filtering string information in scripts. Usually because I pull it from GMCP that way.
Example (one of many places where this has been a hitch):
for k,v in pairs(gmcp.Char.Vitals.charstats) do
if k == 2 then
LTMRageNumber = v
end
end
This makes LTMRageNumber (or v if you want to be simple) equal "Rage: #". The number being whatever value Rage currently is. Problem is, in this example, I'd want to filter out the "Rage: " part. How the heck do I do that? Much love to anyone who can help with this.
0
Comments
Though you should use string.starts(v, "Rage") rather than k == 2.
Results of disembowel testing | Knight limb counter | GMCP AB files
Edit: Or antonius can ninja me like a coding master. w/e
for k,v in pairs(gmcp.Char.Vitals.charstats) do
if k == 2 then
LTMRageNumber = v
end
end
is the same as
LTMRageNumber = gmcp.Char.Vitals.charstats[2]
Unless you use Antonius' idea to get the specific rage one if it ever changes, then a loop is useful.
Site: https://github.com/trevize-achaea/scripts/releases
Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
@Medi Thanks all the same!! Much appreciated.
@Antonius First off, thanks a ton. Seriously! That works flawlessly, and Regex drives me up a wall every time. Also for the fact that I completely missed that string.starts() would be useful there (I blame tunnel vision). Unfortunately I don't get why the regex pattern (%d+) works. I spent a good bit of time digging through online docs and didn't see anything about the % being used in anything but a literal manner, and the online tester that I use (regexpal) completely ignores it, requiring (\d+) instead....which doesn't work at all in Mudlet. Would you mind enlightening me on that, please?
http://www.lua.org/manual/5.1/manual.html#5.4.1
http://lua-users.org/wiki/PatternsTutorial
Lua uses patterns, but they're -not- regex (POSIX) for reasons of speed. Lua uses a very simplified version that is similar but smaller.
These are the character classes it allows:
. all characters
As with regex, capitalize to reverse.
( ) . % + - * ? [ ^ $
As you note by the character classes, treat % like you would \ in normal regex. Begin classes or escape stuff. [] acts like you'd expect - custom charsets. Use ^ starting a charset to reverse it (like capitalizing the simplified charsets above). You can use - to create ranges in charsets as well. () captures just like regex, ^ and $ capture start and end of a line.
Quantifiers are simpler and similar, but different as well. Plus and asterisk are one or more and zero or more, just like regex. A question mark acts like regex, zero or one. A dash acts like a non-greedy asterisk. One or more, but matches the least instead of the most. Equivalent to *? in regex.
%b matches balanced strings, NOT word boundaries. That's a bit of an odd subject if you're only used to regex for triggers and such, but it comes in very handy sometimes. Not something you'd likely use often in MUD scripting though.
Shout if you have any questions!
Site: https://github.com/trevize-achaea/scripts/releases
Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
Lua, which is used for scripting, does not and instead uses the pattern matching described above.
Site: https://github.com/trevize-achaea/scripts/releases
Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
Also, yeah, I'd prefer not to gamble on the fact that the == 2 part will hold forever. Especially since I do plan to share this UI at some point (is an old thread around here about it). 8+ months away didn't change that notion. Just stalled it horribly!
Can't say it enough that I appreciate the help from everyone. With the changes between the time I was here before and now I have a lot to edit. Not to mention getting back to squashing bugs and adding in features I wanted to. So I'm sure I'll have to give a yell again.
In short order you'll be teaching everyone else.
Site: https://github.com/trevize-achaea/scripts/releases
Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
GMCP documentation: https://github.com/keneanung/GMCPAdditions
svof github site: https://github.com/svof/svof and documentation at https://svof.github.io/svof