-
Posted by Mewbaraue on Sun, 10 Aug 2008 05:47:16
XSSFilter could not parse (X)HTML: <p>I've been reading the "World of Warcraft Programming" book, and I'm trying to make that CombatTracker addon work. But whenever I'm logging on, I get the error: Interface\AddOns\CombatTracker\CombatTracker.lua:45: '=' expected near 'CombatTracker_UpdateText'</p> <p>Now I don't know if I'm allowed to post addon code here, but the code we're talking about is this:</p> <p><code> <p>-- Set up some local variables to track time and damage<br />local start_time = 0<br />local end_time = 0<br />local total_time = 0<br />local total_damage = 0<br />local average_dps = 0</p> <p>function CombatTracker_OnLoad(frame)<br /> frame:RegisterEvent("UNIT_COMBAT")<br /> frame:RegisterEvent("PLAYER_REGEN_ENABLED")<br /> frame:RegisterEvent("PLAYER_REGEN_DISABLED")<br /> frame:RegisterForClicks("RightButtonUp")<br /> frame:RegisterForDrag("LeftButton")<br />end</p> <p>function CombatTracker_OnEvent(frame, event, ...)<br /> if event == "PLAYER_REGEN_ENABLED" then<br /> -- This event is called when the player exits combat<br /> end_time = GetTime()<br /> total_time = end_time - start_time<br /> average_dps = total_damage / total time<br /> = CombatTracker_UpdateText()<br /> elseif event == "PLAYER_REGEN_DISABLED" then<br /> -- This event is called when we enter combat<br /> -- Reset the damage total and start the timer<br /> CombatTrackerFrameText:SetText("In Combat")<br /> total_damage = 0<br /> start_time = GetTime()<br /> elseif event == "UNIT_COMBAT" then<br /> if not InCombatLockdown() then<br /> -- We are not in combat so ignore the event<br /> else<br /> local unit,action,modifier,damage,damagetype = ...<br /> if unit == "player" and action ~= "HEAL" then<br /> total_damage = total_damage + damage<br /> end_time = GetTime()<br /> total_time = end_time - start_time<br /> average_dps = total_damage / total_time<br /> CombatTracker_UpdateText()<br /> end<br /> end<br /> end<br />end</p> <p>funtion CombatTracker_UpdateText()<br /> local status = string.format("%ds / %d dmg / %.2f DPS", total_time, total_damage, average_dps)<br /> CombatTrackerFrameText:SetText(status)<br />end</p> <p>funtion CombatTracker_ReportDPS()<br /> local msgformat = "%d seconds spent in combat with %d incoming damage. Average incoming DPS was %.2f"<br /> local msg = string.format(msg.format, total_time, total_damage, average_dps)<br /> if GetNumPartyMember() > 0 then<br /> SendChatMessage(msg, "PARTY")<br /> else<br /> ChatFrame1:AddMessage(msg)<br /> end<br />end</p> <p></code></p></p> <p>Now I want to know if anyone can help me with this problem, and what I'm doing wrong.</p> <p>Another problem is that the CombatTracker frame won't show up anywhere. I've copied the code directly from the book, and I don't get why it won't work. If anyone can help with that too, then I'd be very grateful ^^</p>
-
Posted by Mewbaraue on Sun, 10 Aug 2008 05:47:16
XSSFilter could not parse (X)HTML: <p>I've been reading the "World of Warcraft Programming" book, and I'm trying to make that CombatTracker addon work. But whenever I'm logging on, I get the error: Interface\AddOns\CombatTracker\CombatTracker.lua:45: '=' expected near 'CombatTracker_UpdateText'</p> <p>Now I don't know if I'm allowed to post addon code here, but the code we're talking about is this:</p> <p><code> <p>-- Set up some local variables to track time and damage<br />local start_time = 0<br />local end_time = 0<br />local total_time = 0<br />local total_damage = 0<br />local average_dps = 0</p> <p>function CombatTracker_OnLoad(frame)<br /> frame:RegisterEvent("UNIT_COMBAT")<br /> frame:RegisterEvent("PLAYER_REGEN_ENABLED")<br /> frame:RegisterEvent("PLAYER_REGEN_DISABLED")<br /> frame:RegisterForClicks("RightButtonUp")<br /> frame:RegisterForDrag("LeftButton")<br />end</p> <p>function CombatTracker_OnEvent(frame, event, ...)<br /> if event == "PLAYER_REGEN_ENABLED" then<br /> -- This event is called when the player exits combat<br /> end_time = GetTime()<br /> total_time = end_time - start_time<br /> average_dps = total_damage / total time<br /> = CombatTracker_UpdateText()<br /> elseif event == "PLAYER_REGEN_DISABLED" then<br /> -- This event is called when we enter combat<br /> -- Reset the damage total and start the timer<br /> CombatTrackerFrameText:SetText("In Combat")<br /> total_damage = 0<br /> start_time = GetTime()<br /> elseif event == "UNIT_COMBAT" then<br /> if not InCombatLockdown() then<br /> -- We are not in combat so ignore the event<br /> else<br /> local unit,action,modifier,damage,damagetype = ...<br /> if unit == "player" and action ~= "HEAL" then<br /> total_damage = total_damage + damage<br /> end_time = GetTime()<br /> total_time = end_time - start_time<br /> average_dps = total_damage / total_time<br /> CombatTracker_UpdateText()<br /> end<br /> end<br /> end<br />end</p> <p>funtion CombatTracker_UpdateText()<br /> local status = string.format("%ds / %d dmg / %.2f DPS", total_time, total_damage, average_dps)<br /> CombatTrackerFrameText:SetText(status)<br />end</p> <p>funtion CombatTracker_ReportDPS()<br /> local msgformat = "%d seconds spent in combat with %d incoming damage. Average incoming DPS was %.2f"<br /> local msg = string.format(msg.format, total_time, total_damage, average_dps)<br /> if GetNumPartyMember() > 0 then<br /> SendChatMessage(msg, "PARTY")<br /> else<br /> ChatFrame1:AddMessage(msg)<br /> end<br />end</p> <p></code></p></p> <p>Now I want to know if anyone can help me with this problem, and what I'm doing wrong.</p> <p>Another problem is that the CombatTracker frame won't show up anywhere. I've copied the code directly from the book, and I don't get why it won't work. If anyone can help with that too, then I'd be very grateful ^^</p>
-
Posted by Mewbaraue on Sun, 10 Aug 2008 05:49:52
btw, here it's line 38 it's talking about. I've used some spaces between the code, which have been deleted here, and for some reason, I'm not allowed to edit my post :/
-
Posted by jnwhiteh on Sun, 10 Aug 2008 08:52:16
There are a few issues with the code you've posted. For reference, you can get the code for the addon itself at the page for the chapter, i.e. http://wowprogramming.com/chapters/first-edition/12.
The problem lines are these:
average_dps = total_damage / total time
= CombatTracker_UpdateText()The first line should read:
average_dps = total_damage / total_time
And the second line should read:
CombatTracker_UpdateText()
Hopefully that clealrs some things up!
-
Posted by Mewbaraue on Mon, 11 Aug 2008 04:25:25
I'll give it a try and see if it works ^^
-
Posted by Mewbaraue on Mon, 11 Aug 2008 04:56:29
I made it work ^^
Turns out that you were right, but there were 2 other problems:
funtion CombatTracker_UpdateText()
funtion CombatTracker_ReportDPS()
That's right... I mispelled "function". I wrote "funtion" instead xD
Ah well, it works now, and that what's important. Thanks again ;)
-
Posted by jnwhiteh on Mon, 11 Aug 2008 08:24:22
Great to hear it!