WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Weird result from string operations on BNet friends (https://www.wowinterface.com/forums/showthread.php?t=50424)

blackytemp 11-10-14 05:16 AM

Weird result from string operations on BNet friends
 
Hello,

I was trying to make a quick addon but stumbled upon this which I can just assume is me doing something really wrong. The plan was to filter BNet friend requests by name etc. I have a function

Code:

        function self:GetFriendInviteName(i)
                local _, r = BNGetFriendInviteInfo(i)
                return r
        end

(this could be done inline but I made it into a separate function in an effort to debug this issue). I now have the Friend invite name and want to match it (looking for the spammy GM0000 type requests). I considered my expression of (GM)([0-9])+ to be at least somewhat correct and wondered why it wasn't matching so I dug a little deeper and these are the results of a macro I used to check:

Macro:

Code:

/run local w = nx_Talents:GetFriendInviteName(1); print(w); print(string.find(w,".......")); print(string.match(w,"......."));
Result:

Code:

|Kb5|kGM6767|k
1 7
|Kb5|k0

Ingame the first result shows as just GM6767 , I assume the rest is coloring? I used a catchall on the macro because previous investigations showed weird results and I wanted to see what's really happening. I have no Idea how to go about matching it correctly and why it doesn't give me the actual name as a string. Thanks in advance for your help.

Choonstertwo 11-10-14 05:39 AM

Most Battle.net functions return |K escape sequences instead of actual real names. These are translated to real names by the client outside of the UI, so AddOns and scripts can't see anything more than the escape sequence.

Presumably the b character represents a BattleTag name instead of a given name, surname or full name.

blackytemp 11-10-14 06:45 AM

Thank you! That explains the weird output. However, I am still having serious issues with the string matching. Even running

Code:

/run local _,w = BNGetFriendInviteInfo(1); print(w); print(string.match(w,"GM"));
Results in:

Code:

|Kb5|kGM6767|k
nil

Even though the output of the variable shows that GM is clearly even in the escaped string. Again using the dots as a catchall (one short of the total string length so I can actually see it in ingame chat) reveals it is somehow using 0's instead when under the string operation (tested with both match and find):

Code:

/run local _,w = BNGetFriendInviteInfo(1); print(w); print(string.match(w,"............."));
Results in:

Code:

|Kb5|kGM6767|k
|Kb5|k000000|

However, if I extend the . wildcards by one for the full length, it suddenly gives back the correct escaped string again. I'm having serious troubles wrapping my head around this, I assume I'm misunderstanding something about the string operations maybe?

Phanx 11-10-14 11:01 PM

The "|k000000|k" sequence is replaced with the real text internally. You can print it or SetText with it and get the expected text shown on the screen, but you can't actually see it in Lua code or manipulate with the Lua string functions. This is intentional, and there is no way around it. Addon code cannot tell what the contents of the "|k" sequence are, period.

It's also worth noting that you can trim the sequence by removing some of the 0 characters (so if "|k00000|k" is "Phanx" then "|k00|k" is just "Ph") but extra 0s are just ignored ("|k00000000000000|k" is still just "Phanx").


All times are GMT -6. The time now is 10:44 AM.

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