WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   special letters (https://www.wowinterface.com/forums/showthread.php?t=45565)

Anja 01-04-13 07:02 AM

special letters
 
Code:

dkp = {
["Fr\195\170em\195\162n"] = 56.00
}

How can i get This value


dkp.playername doenst work with special letters, can i first convert the playername string to this \170\162 Stuff? to get the right array key?

something like...

Code:

s = Frêemân
local function convert(s)


 return s -- like Fr\195\170em\195\162n
end


humfras 01-04-13 09:13 AM

dkp.blabla is the same as dkp["blabla"].

For a string value, use (e.g.)

local s = "blabla"
local val = dkp[s]

Anja 01-04-13 09:40 AM

but when the string value is with special character like é or â then i didnt find the array key because of this \015\102 in it, how can i convert the á into \016 ?! to match the key in the array?!

Dridzt 01-04-13 10:19 AM

If we're talking about an in-game addon (.lua) then making sure you save your file as utf8 should suffice for saving and looking up keys without escaping characters.

That is save as [blâblâ] and look it up the same way.

If you have a web interface parsing saved variables, or you need to copy paste from in-game to a web site or some other interaction of the kind, provide more information about what exactly you're trying to accomplish and in what environment :)

Tim 01-04-13 10:48 AM

Yeah the question here is why your string contains utf8 format instead of plain text. As Driz asked, are you using an external dkp extracting addon or something?

Saving as...
Code:

dkp = {
["Frêemân"] = 56.00
}

and then grabbing the data by..
Code:

dkp["Frêemân"]
If it's a must to where you have to use utf8 then you would want to create a table with all the special characters in it with their utf format and then making a replace/convert function to use that table.

Anja 01-04-13 10:54 AM

yepp the data format ist only like

["B\195\162be"] or
["Dw\195\161yna"] = {
["DKP"] = 100.00
}

the data comes from http://absence-gilde.com/eqdkp/getdkp.php eqdkp
the old addon "GetDKP" doesnt work, so i codet my own little "whisper to get dkp" addon.

it works fine, (with my very bad code *g*) but the utf8 problem let it only work for normal character names.

Code:

SLASH_DKP1 = "/dkp"
SlashCmdList["DKP"] = function(msg, editBox)
    -- change the text on the editBox.
    print("Du hast "..gdkp.players.Ikuria.DKP.. "DKP")
end

local function filter(self, event, msg, sender)
        split = string.match(msg, " (%w+)")
        if (split) then
        firstchar = split:sub(1,1)
        firstchar = firstchar:upper()
        split = split:sub(2)
        split = firstchar .. split
        end
        if (self:GetName() == "ChatFrame1") then
                if (gdkp.players[split]) then
                        SendChatMessage(split.." hat "..gdkp.players[split].DKP.. " DKP aus ".. gdkp.players[split].rcount .. " gespielten Raids.", "WHISPER", nil, sender)
                        return true
                else
                        if (msg == "!dkp" or msg == "?dkp") then
                                if (gdkp.players[sender]) then
                                        SendChatMessage("Du hast "..gdkp.players[sender].DKP.. " DKP aus ".. gdkp.players[sender].rcount .. " gespielten Raids.", "WHISPER", nil, sender)
                                        return true
                                else
                                        SendChatMessage("Der Spieler "..sender.. " wurde nicht gefunden.", "WHISPER", nil, sender)
                                        return true
                                end
                        end
                end
        end
        if (self:GetName() == "ChatFrame5") then
                if (gdkp.players[split] or msg == "!dkp" or msg == "?dkp") then
                        return true
                end
        end
end


local function HideOutgoing(self, event, msg, author, ...)
        if (self:GetName() == "ChatFrame5") then
                if (msg == string.match(msg, "Du hast %d+ DKP aus %d+ gespielten Raids.")) then
                        UIErrorsFrame:AddMessage(author.." fragte seine DKP ab.", 1.0, 0.0, 0.0, 53, 5);
                        return true       
                end
                if (msg == string.match(msg, "%w+ hat %d+ DKP aus %d+ gespielten Raids.")) then
                        split = string.match(msg, "(%w+)")
                        firstchar = split:sub(1,1)
                        firstchar = firstchar:upper()
                        split = split:sub(2)
                        split = firstchar .. split
                        UIErrorsFrame:AddMessage(author.." fragte "..split.."'s DKP ab.", 1.0, 0.0, 0.0, 53, 5);
                        return true
                end
                if (msg == string.match(msg, "Der Spieler %w+ wurde nicht gefunden.")) then
                        return true
                end
        else
                return true
        end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", HideOutgoing)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filter)


semlar 01-04-13 03:16 PM

Lua Code:
  1. local function convert(s)
  2.     return (gsub(s, '.', function(c) local o = string.byte(c) return o > 127 and '\\' .. o or c end))
  3. end

Anja 01-04-13 04:33 PM

someone helped me in private message, for those who search for the same answer

i used the wrong regex
%w finds only normal letters

string.match(msg, "(.+)")

finds the rest ;)

SDPhantom 01-04-13 06:30 PM

Quote:

Originally Posted by Cirax (Post 271334)
Yeah the question here is why your string contains utf8 format instead of plain text.

If it's a must to where you have to use utf8 then you would want to create a table with all the special characters in it with their utf format and then making a replace/convert function to use that table.

All strings WoW passes into the Lua environment are encoded in UTF-8. Since UTF-8 was created to be backwards compatible with ANSI, any codes within the ANSI character set will be exactly the same in UTF-8. Also, there's no reason to need a conversion function to store these in Lua. Lua supports full binary in its strings, even embedded zeroes.



Quote:

Originally Posted by Anja (Post 271346)
someone helped me in private message, for those who search for the same answer

i used the wrong regex
%w finds only normal letters

string.match(msg,"(.+)")

finds the rest ;)

The result of (.+) returns the entire contents of the string msg as it matches all characters. I would recommend using the non-space identifier (%S+) instead. Note these identifiers are case sensitive in which using the opposite case returns an inverse match. For example, since the lowercase %s returns any whitespace character, the uppercase %S would return any non-whitespace character.

Anja 01-04-13 07:32 PM

Lua Code:
  1. SLASH_DKP1 = "/dkp"
  2. SlashCmdList["DKP"] = function(msg, editBox)
  3.     -- change the text on the editBox.
  4.     print("Du hast "..gdkp.players.Ikuria.DKP.. "DKP")
  5. end
  6.  
  7. local function filter(self, event, msg, sender)
  8.     split = string.match(msg, " (%S+)")
  9.     if (split) then
  10.     firstchar = split:sub(1,1)
  11.     firstchar = firstchar:upper()
  12.     split = split:sub(2)
  13.     split = firstchar .. split
  14.     end
  15.     if (self:GetName() == "ChatFrame5") then
  16.         if (msg == "!dkp" or msg == "?dkp") then
  17.             if (gdkp.players[sender]) then
  18.                 SendChatMessage("Du hast "..gdkp.players[sender].DKP.. " DKP aus ".. gdkp.players[sender].rcount .. " Std. gespielter Raidzeit.", "WHISPER", nil, sender)
  19.                 return true
  20.             else
  21.                 SendChatMessage("Der Spieler "..sender.. " wurde nicht gefunden.", "WHISPER", nil, sender)
  22.                 return true
  23.             end
  24.         elseif (gdkp.players[split]) then
  25.             SendChatMessage(split.." hat "..gdkp.players[split].DKP.. " DKP aus ".. gdkp.players[split].rcount .. " Std. gespielter Raidzeit.", "WHISPER", nil, sender)
  26.             return true
  27.         end
  28.     else
  29.         if (msg == "!dkp" or msg == "?dkp") then
  30.             return true
  31.         end
  32.     end
  33. end
  34.  
  35.  
  36. local function HideOutgoing(self, event, msg, author, ...)
  37.     if (self:GetName() == "ChatFrame5") then
  38.         if (msg == string.match(msg, "Du hast %d+ DKP aus %d+ Std. gespielter Raidzeit")) then
  39.             UIErrorsFrame:AddMessage(author.." fragte seine DKP ab.", 1.0, 0.0, 0.0, 53, 5);
  40.             return true
  41.         elseif (msg == string.match(msg, ".+ hat %d+ DKP aus %d+ Std. gespielter Raidzeit.")) then
  42.             split = string.match(msg, "(%S+) hat .+")
  43.             UIErrorsFrame:AddMessage(author.." fragte "..split.."'s DKP ab.", 1.0, 0.0, 0.0, 53, 5);
  44.             return true
  45.         elseif (msg == string.match(msg, "Der Spieler (%S+) wurde nicht gefunden.")) then
  46.             return true
  47.         end
  48.     else
  49.         return true
  50.     end
  51. end
  52.  
  53. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", HideOutgoing)
  54. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filter)

works, but the code is little messie ^^ just because of the "ChatFrame5" thing, i didnt know how to prevent the double posts because of same whispers in more tabs :(

sry for my problems here, i'm just learning lua at the moment ^^

SDPhantom 01-07-13 06:13 PM

I would actually recommend moving your whisper reply code into its own frame and handler. The problem with putting it in with the rest of your filter functions is those functions run for every ChatFrame that has the whisper event registered.

Another problem is if no ChatFrames are registered with the whisper event, the filter functions will never run.


All times are GMT -6. The time now is 04:00 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI