Here is actually a *working* example, but notice there are 2 commented out conditional statements. With them commented, it works. With them in it doesn't. This leads me to think it may in fact be a performance issue because when I run the whole item (not copied here) with them commented out, it still doesn't run. So these 2 lines can break the item, but removing them doesn't necessarily fix it...
With the conditionals commented, this code will interpret any binary bytes it finds in the CHAT_MSG_SAY channel.
Apologies for my self-taught, brute-force approach here - and thanks in advance for any time and tips you have!
(note there is one conditional - GHI_CountBuffs - that requires GHI..)
Code:
local word_table = {}
if not binbrewFrame then
binbrewFrame = CreateFrame("Frame");
end
binbrewFrame:RegisterEvent("CHAT_MSG_SAY");
local binBrewFunc = function (self, event, ...)
local message, sender, language, channelString, target, flags, unknown, channelNumber, channelName, unknown, counter = ...
local msgSearch = string.find(message, "[bB]inary");
-- if GHI_CountBuffs("Binary") > 0 then
-- if msgSearch ~= nil then
local array2 = {}
local array3 = {}
for wurd in message:gmatch("%S+") do table.insert(array3, wurd) end
for k,v in pairs(array3) do
local incr = 1
local array4 = {}
local tByte = ""
local altr = ""
local actual_word = ""
for w in string.gmatch(v, ".") do
tByte = tByte .. w
local sum = 0
if incr%7==0 then
array4[incr/7] = tByte
local bin = string.reverse(array4[incr/7])
for i = 1, string.len(bin) do
num = string.sub(bin, i,i) == "1" and 1 or 0
sum = sum + num * math.pow(2, i-1)
end
tByte=""
altr = string.char(sum)
actual_word = actual_word .. altr
end
incr = incr + 1
end
word_table[k] = actual_word
end
local sentence = ""
for i=1, #word_table, 1 do
sentence = sentence .. word_table[i]
end
print(sentence)
-- end
-- end
end
binbrewFrame:SetScript("OnEvent", binBrewFunc);