WoW:Parsing event messages: Difference between revisions

m
Move page script moved page Parsing event messages to WoW:Parsing event messages without leaving a redirect
m (Move page script moved page Parsing event messages to WoW:Parsing event messages without leaving a redirect)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{wikify}}
{{wow/uihowto}}
 
Event messages are things like combat log messages, loot messages, online/offline notifications, and so on.
Event messages are things like combat log messages, loot messages, online/offline notifications, and so on.


Line 9: Line 8:
In order to get this information, you need to parse the big long string.
In order to get this information, you need to parse the big long string.


== What's the quick-and-dirty way to parse an event message? ==
== Parsing messages the quick way ==
What's the quick-and-dirty way to parse an event message?


Well, you can look at how the event message looks, and you can manually write a string.find over that string to extract the information you need.  For example,
Well, you can look at how the event message looks, and you can manually write a string.find over that string to extract the information you need.  For example,
Line 48: Line 48:
  end
  end


== What's the clean-and-easy way? ==
== Parsing messages the clean way ==
What's the clean-and-easy way?


Well, first, you should extract GlobalStrings.lua out of your WoW install.  Then, you will want to look through that file for the variable that contains the template of the message you're looking for.  In our case, it is
Well, first, you should extract GlobalStrings.lua out of your WoW install.  Then, you will want to look through that file for the variable that contains the template of the message you're looking for.  In our case, it is
Line 80: Line 81:
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? ==
== Parsing messages the right way ==
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.
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:
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)", "(.+)")
  newpattern = string.gsub(string.gsub(FACTION_STANDING_INCREASED, "(%%s)", "(.+)"), "(%%d)", "(.+)")
  start, end, faction, amount = string.find(string, newpattern)
  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.
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