Navigation menu

WoW:Parsing event messages: Difference between revisions

Jump to navigation Jump to search
The Clean-And-Not-So-Easy way
m (Bot: Fixing wiki syntax)
(The Clean-And-Not-So-Easy way)
Line 85: Line 85:


MarsMessageParser will take care of reading the GlobalStrings.lua, creating the correct pattern for the current locale, re-ordering the parameters accordingly, and finally calling MyHonorTrackingFunction with three parameters: killed, rank, and honor.
MarsMessageParser will take care of reading the GlobalStrings.lua, creating the correct pattern for the current locale, re-ordering the parameters accordingly, and finally calling MyHonorTrackingFunction with three parameters: killed, rank, and honor.
== What's the Clean-And-Not-So-Easy way? ==
If you don't want to download the MarsMessageParser and include it in your addon, the thing you're left to do is find a way to do it yourself. But rather than develop a ton of code, you just want to "hardwire" your addon for just the string you want to use, rather than the infinite amount of infinite variables in every string in GlobalStrings.lua.
Well, let's look at FACTION_STANDING_INCREASED. According to GlobalStrings.lua, this says "Reputation with %s increased by %d." Well, to make it work like the strings at the top, we'd need to replace %s and %d with (.+). But how do we do that? Here's how:
newpattern = string.gsub(string.gsub(FACTION_STANDING_DECREASED, "(%%s)", "(.+)"), "(%%d)", "(.+)")
start, end, faction, amount = string.find(string, newpattern)
This example will properly parse the string, and return all the information we need. How was this achieved? By using a % in front of the %s, it tells it to look for %s in stead of a space, which is what %s would normally be looking for. This way, even though we have to hardcode in the strings we want, we can also don't have to bother with translations.
[[Category:HOWTOs|Parse Event Messages]]
[[Category:HOWTOs|Parse Event Messages]]
Anonymous user