Hello, I tried to get flag carrier class in Warsong gulch, it worked few days ago but now I don't know why doesn't work anymore.... I haven't changed anything. I use in update :
for i=1,GetNumBattlefieldScores() do
local name,_,_,_,_,_,_,_,class = GetBattlefieldScore(i);
if (strmatch(name,CarrierName)) then
table.class = class;
end
end
and it doesn't work.... strmatch always return nil even if name and CarrierName are same...
it is strange I tried to print(name,CarrierName), both are exactly the same but table.class is always nil...
Hello, I tried to get flag carrier class in Warsong gulch, it worked few days ago but now I don't know why doesn't work anymore.... I haven't changed anything. I use in update :
for i=1,GetNumBattlefieldScores() do
local name,_,_,_,_,_,_,_,class = GetBattlefieldScore(i);
if (strmatch(name,CarrierName)) then
table.class = class;
end
end
and it doesn't work.... strmatch always return nil even if name and CarrierName are same...
it is strange I tried to print(name,CarrierName), both are exactly the same but table.class is always nil...
Do you know why ?
thanks
Uh... name == CarrierName. Also, table is a really bad name for a variable.
there aren't names I use in the addon it's to be clear in the the forum
He was suggesting that you do this:
for i=1,GetNumBattlefieldScores() do
local name,_,_,_,_,_,_,_,class = GetBattlefieldScore(i);
if name == CarrierName then
table.class = class;
end
end
strmatch isn't really designed to do what you're using it for. It could potentially give erronious results.....for example
name = "Babubbu"
CarrierName = "bubbu"
strmatch would return something other than nil even though they aren't the same.
Not saying that's your problem but it's going to be a source of bugs. It's it's very likely that somewhere in that loop or related code it's leading to the issue.
It would also explain why it "used" to work, which is because you've been lucky with the names of the players in the battlefield!
no I have a big table in a file like localisation file, and I put everything in it, for example my table is named "Mytable" and it is loaded when addon load
when CHAT_MESSAGE_BG_SYSTEM_ALLIANCE event I get flag carrier name and I put it in MyTable.Name[1]
and I want to do same for the class in MyTable.Class[1]
I know strmatch can find something else the thing I'm looking for but I don't think it is the problem
but i'm going to try name == CarrierName
edit : no name == CarrierName won't work because name is sometimes Batman-Ysondre.. the name and the server
Even though you don't think it's the problem, fix the comparison check, because it's a real problem.
Then just retest and see what happens. If it's still an issue then post your unmodified code. I realize you were just trying to make it more clear but it could be that the problem is in your real code, not the modified code you posted.
if (Ll.CarrierName[1]=="") then
Ll.CarrierClass[1] = "";
Frame026:Hide();
FrameText026:SetText("");
Frame026:SetAttribute("macrotext",format("/target %s",""));
else
Frame026:Show();
FrameText026:SetText(Ll.CarrierName[1]);
Frame026:SetAttribute("macrotext",format("/target %s",Ll.CarrierName[1]));
for i=1,GetNumBattlefieldScores() do
local Name,_,_,_,_,_,_,_,class = GetBattlefieldScore(i);
if (strmatch(Name,Ll.CarrierName[1])) then
FrameText026:SetTextColor(ColorCarrier(class));
end
end
end
where Ll is the big table, ColorCarrier is a function which return class color (it seems to work)
Just an FYI: There's absolutely no reason why anybody needs to dumb down their code. Someone once compared program code to the Matrix. Where laymen see lines of text, we see a picture.
That being said, either link to your project in it's current "broken" state or use http://paste.wowace.com/ to paste your entire raw unmodified code.
Also, have you tried "==" rather than strmatch() or are you going to be stubborn and assume that it won't work despite the fact that you came here looking for help.
Just an FYI: There's absolutely no reason why anybody needs to dumb down their code. Someone once compared program code to the Matrix. Where laymen see lines of text, we see a picture.
sorry i only intend to show the problem quickly
for the "==" I know it won't work because if the player carrying the flag is in another server getbattlefieldscore returns Name-Server but may be I can format to keep only Name I'm going to try thank you
for the "==" I know it won't work because if the player carrying the flag is in another server getbattlefieldscore returns Name-Server but may be I can format to keep only Name I'm going to try thank you
Oh good point. You should still consider tightening down the comparison using whatever means you find best. Even doing a left comparison, or ensuring that CarrierName[1] contains the server name so that == will work, etc.
how are you extracting the name from the battleground message?
i take it, you've inserted a print command to verify they are the same. i would add a string.length() for each as well just to ensure that there's not some escape code funny business going on.
also, while it's not an issue here, if you're just testing two strings and you don't need the result, string.find() is a better function to use over string.match(). string.match() potentially creates a new string rather than just identifying where the first can be found in the second.
how are you extracting the name from the battleground message?
i take it, you've inserted a print command to verify they are the same. i would add a string.length() for each as well just to ensure that there's not some escape code funny business going on.
yes it was the function to extract the name which had a problem -_-... I use string.len and there are 2 excess spaces...
so I have to format name from getbattlefieldscore() to have only the name, and then use string.match (because I can't remove the 2 excess spaces I don't know how)
yes it was the function to extract the name which had a problem -_-... I use string.len and there are 2 excess spaces...
so I have to format name from getbattlefieldscore() to have only the name, and then use string.match (because I can't remove the 2 excess spaces I don't know how)
thank you
if the spaces are always in the same place, you can just do a string.sub() to cut out the piece you want. of course, fixing your pattern match would be better.
i'm no string pattern genius, but i'm thinking this would work:
local toonName = string.match(message,"picked up by (.+)%.")
if not that, then maybe:
local toonName = string.match(message,"picked up by (%P+)")
for i = 1, GetNumBattlefieldScores() do
local name, killingBlows, honorKills, deaths, honorGained, faction, rank, race, class, filename, damageDone, healingDone = GetBattlefieldScore(i);
if name then
local plr, svr = name:match("([^%-]+)%-?(.*)")
end
end
Erm, you know there is already a string.trim function in WoW Lua, right? >_>
s = s:trim()
s = string.trim(s)
Removes all spaces from the beginning and end of the string.
It's also a little different than what egingell was talking about, which was removing multiple consecutive spaces from the string, not just spaces at the beginning and end. ;)
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
and it doesn't work.... strmatch always return nil even if name and CarrierName are same...
it is strange I tried to print(name,CarrierName), both are exactly the same but table.class is always nil...
Do you know why ?
thanks
He was suggesting that you do this:
strmatch isn't really designed to do what you're using it for. It could potentially give erronious results.....for example
name = "Babubbu"
CarrierName = "bubbu"
strmatch would return something other than nil even though they aren't the same.
Not saying that's your problem but it's going to be a source of bugs. It's it's very likely that somewhere in that loop or related code it's leading to the issue.
It would also explain why it "used" to work, which is because you've been lucky with the names of the players in the battlefield!
when CHAT_MESSAGE_BG_SYSTEM_ALLIANCE event I get flag carrier name and I put it in MyTable.Name[1]
and I want to do same for the class in MyTable.Class[1]
I know strmatch can find something else the thing I'm looking for but I don't think it is the problem
but i'm going to try name == CarrierName
edit : no name == CarrierName won't work because name is sometimes Batman-Ysondre.. the name and the server
Then just retest and see what happens. If it's still an issue then post your unmodified code. I realize you were just trying to make it more clear but it could be that the problem is in your real code, not the modified code you posted.
where Ll is the big table, ColorCarrier is a function which return class color (it seems to work)
That being said, either link to your project in it's current "broken" state or use http://paste.wowace.com/ to paste your entire raw unmodified code.
Also, have you tried "==" rather than strmatch() or are you going to be stubborn and assume that it won't work despite the fact that you came here looking for help.
sorry i only intend to show the problem quickly
for the "==" I know it won't work because if the player carrying the flag is in another server getbattlefieldscore returns Name-Server but may be I can format to keep only Name I'm going to try thank you
Oh good point. You should still consider tightening down the comparison using whatever means you find best. Even doing a left comparison, or ensuring that CarrierName[1] contains the server name so that == will work, etc.
Good luck :)
This sounds so .. cool for some reason
I forget who originally made the comparison. Maybe Xinhuan or Torhal.
i take it, you've inserted a print command to verify they are the same. i would add a string.length() for each as well just to ensure that there's not some escape code funny business going on.
also, while it's not an issue here, if you're just testing two strings and you don't need the result, string.find() is a better function to use over string.match(). string.match() potentially creates a new string rather than just identifying where the first can be found in the second.
yes it was the function to extract the name which had a problem -_-... I use string.len and there are 2 excess spaces...
so I have to format name from getbattlefieldscore() to have only the name, and then use string.match (because I can't remove the 2 excess spaces I don't know how)
thank you
if the spaces are always in the same place, you can just do a string.sub() to cut out the piece you want. of course, fixing your pattern match would be better.
i'm no string pattern genius, but i'm thinking this would work:
local toonName = string.match(message,"picked up by (.+)%.")
if not that, then maybe:
local toonName = string.match(message,"picked up by (%P+)")
local function Trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
s = s:trim()
s = string.trim(s)
Removes all spaces from the beginning and end of the string.
It's also a little different than what egingell was talking about, which was removing multiple consecutive spaces from the string, not just spaces at the beginning and end. ;)