Thread Tools Display Modes
10/26/14, 11:59 AM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
My code is acting up

Here is the thing I got my code working however it's not working at the entry of a new zone. The addon I'm working on is pretty simple. When you go to a zone it just pulls up a little info that lets you know how many quest that are there. I added the quest list myself using esohead and a little typing magic lol. But to give you an idea of what is happining when I go from one zone to another the addon doesn't update when you get to the new zone. I had to type /reloadui to get it to load the zone. I'll leave my code below so you can have a better look at it.

lua

Lua Code:
  1. QuestVars = {}
  2.  
  3. QuestVars.Defaults = {
  4.     ["hideQuest"] = false,
  5.     ["Quest"] = {
  6.         ["offsetx"] = 0,
  7.         ["offsety"] = 0,
  8.         ["point"] = TOPLEFT,
  9.         ["relPoint"] = TOPLEFT,
  10.         },
  11. }
  12.  
  13. local quests ={
  14. --Aldmeri Dominion
  15.     ["Auridon"] = 51,
  16.     ["Khenarthi's Roost"] = 11,
  17.     ["Grahtwood"] = 44,
  18.     ["Greenshade"] = 50,
  19.     ["Malabal Tor"]= 45,
  20.     ["Reaper's March"] = 60,
  21.     ["Coldharbour"] = 32,
  22.  
  23. --Daggerfall Covenant
  24.     ["Stros M'Kai"] = 15,
  25.     ["Betnikh"] = 9,
  26.     ["Glenumbra"] = 67,
  27.     ["Stormhaven"] = 70,
  28.     ["Rivenspir"] = 48,
  29.     ["Alik'r Desert"] = 53,
  30.     ["Bangkorai"] = 47,
  31.    
  32. --Ebonheart Pact
  33.     ["Bleakrock Isle"] = 12,
  34.     ["Bal Foyen"] = 9,
  35.     ["Stonefalls"] = 76,
  36.     ["Deshaan"] = 67,
  37.     ["Shadowfen"] = 64,
  38.     ["Eastmarch"] = 52,
  39.     ["The Rift"] = 73,
  40.  
  41. --Quest For All Factions
  42.     ["Coldharbour"] = 32,
  43.    
  44. --Guild Quest
  45.     --["Fighters Guild"] = 5,
  46.     --["Mages Guild"] = 8,
  47. }
  48.  
  49. --Function for pulling up zone and how many quests, QuestZone will be the name of the function connecting to line 26
  50.  
  51.  
  52. local function ZoneQuest()
  53.         local myZone = GetUnitZone("player")
  54.         local numQuests = quests[myZone]
  55.         QuestLurkerQuest:SetText(myZone..": "..numQuests)
  56. end
  57.  
  58. local function OnMoveStopQuest()
  59.     _, QuestVars.SV.Quest.point, _, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx, QuestVars.SV.Quest.offsety = QuestLurker:GetAnchor(0)
  60. end
  61.  
  62. local function LoadSavedVars()
  63.     QuestLurker:SetAnchor(QuestVars.SV.Quest.point, nil, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx, QuestVars.SV.Quest.offsety)
  64. end
  65.  
  66. local function OnAddOnLoaded(eventCode, addon)
  67.     if addon == "QuestLurker" then
  68.         QuestVars.SV = ZO_SavedVars:New( "Que_Variables" , 2 , nil , QuestVars.Defaults , nil )
  69.         if (QuestVars.SV ~= nil) then
  70.                LoadSavedVars()
  71.         end
  72.         QuestLurker:SetHandler("OnMoveStop", OnMoveStopQuest)
  73.         --QuestLurker:SetHandler("OnMouseDown", MyAddonQuestZone)
  74.         EVENT_MANAGER:RegisterForEvent("QuestLurkerZone", EVENT_ZONE_CHANGED, ZoneQuest)
  75.         ZoneQuest()
  76.     end
  77. end
  78.  
  79.  
  80. EVENT_MANAGER:RegisterForEvent("QuestLurker", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

xml

Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="QuestLurker" mouseEnabled="true" movable="true" hidden="false" resizeToFitDescendents="true">       
  4.                 <Controls>
  5.                 <Backdrop name="$(parent)BG" inherits="ZO_ThinBackdrop" excludeFromResizeToFitExtents="true">
  6.                     <AnchorFill />
  7.                 </Backdrop>
  8.                
  9.                 <Label name="$(parent)Quest" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" horizontalAlignment="CENTER">
  10.                     <Anchor point="CENTER" realtiveTo="$(parent)" realtivePoint="CENTER" offsetX="0" offsetY="0" />
  11.                 </Label>
  12.             </Controls>
  13.         </TopLevelControl>
  14.     </Controls>
  15. </GuiXml>

txt

Lua Code:
  1. ## Title: |cFFFFB0QuestLurker|r 1.0 by - |c00C000Zireko & KatKat42|r
  2. ## APIVersion: 100009
  3. ## Description: QuestLurker lets you know how many quest are in the current zone you are in. This Addon will work great with other addons that let you know what quests you have finished.
  4. ## Version: 1.0
  5. ## SavedVariables: Que_Variables
  6.  
  7. QuestLurker.xml
  8. QuestLurker.lua

If you see what is wrong try and explain in the simplest way possible. I'm still new to coding and explanations help me a lot.
  Reply With Quote
10/27/14, 12:13 AM   #2
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Here is what I see:

you have
Lua Code:
  1. local function OnAddOnLoaded(eventCode, addon)
  2. ...
  3. -- Specifically refering to the line below,
  4. ZoneQuest()
  5. ...
If your wanting that to fire, to print the zoneName when the user logs in you need to do it after the player Activated event by adding:

Lua Code:
  1. -- Add this to make it print the zone when the char activates:
  2. local function OnPlayerActivated()
  3.         ZoneQuest()
  4. end
  5. local function OnAddOnLoaded(eventCode, addon)
  6.    if addon == "QuestLurker" then
  7.    ....
  8.    -- Add this to make it print the zone when the char activates:
  9.    EVENT_MANAGER:RegisterForEvent("QuestLurker", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  10.    ...



You might want to add clampedToScreen to the control so it can't go off of the screen
and give your window a starting dimension & anchor point in your xml file
Lua Code:
  1. <TopLevelControl name="QuestLurker" clampedToScreen="true"  mouseEnabled="true" movable="true" hidden="false" resizeToFitDescendents="true">  
  2.    <Dimensions x="150" y="150" />
  3.    <Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="TOPLEFT" offsetX="50" offsetY="50"/>  
  4.    ...


Make this local, It only holds the defaults, no reason for it to be accessible globally
Lua Code:
  1. local QuestVars.Defaults = { ....}


And there are a couple of small errors here too:
Lua Code:
  1. local function OnMoveStopQuest()
  2.     -- Change This:
  3.     -- _, QuestVars.SV.Quest.point, _, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx, QuestVars.SV.Quest.offsety = QuestLurker:GetAnchor(0)
  4.    
  5.     -- To This:
  6.     -- Even if you dont want those values that are returned, define them so they are local
  7.     -- You don't want to leave the _'s open to the global namespace)
  8.     local bIsValid, relativeTo
  9.     bIsValid, QuestVars.SV.Quest.point, relativeTo, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx, QuestVars.SV.Quest.offsety = QuestLurker:GetAnchor(0)
  10. end
  11.  
  12. local function LoadSavedVars()
  13.     -- Always clear anchors before setting them
  14.     QuestLurker:ClearAnchors()
  15.    
  16.     QuestLurker:SetAnchor(QuestVars.SV.Quest.point, nil, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx,QuestVars.SV.Quest.offsety)
  17. end


Lua Code:
  1. local function OnAddOnLoaded(eventCode, addon)
  2.     if addon == "QuestLurker" then
  3.         QuestVars.SV = ZO_SavedVars:New( "Que_Variables" , 2 , nil , QuestVars.Defaults , nil )
  4.         if (QuestVars.SV ~= nil) then
  5.             LoadSavedVars()
  6.         end
  7.         QuestLurker:SetHandler("OnMoveStop", OnMoveStopQuest)
  8.         QuestLurker:SetHandler("OnMouseDown", MyAddonQuestZone)
  9.        
  10.         -- Add this to make it print the zone when the char activates:
  11.         EVENT_MANAGER:RegisterForEvent("QuestLurker", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  12.         -- Change this line:
  13.         EVENT_MANAGER:RegisterForEvent("QuestLurker", EVENT_ZONE_CHANGED, ZoneQuest)
  14.        
  15.         -- Add this to unregister your OnAddOnLoaded (it only needs to load once):
  16.         EVENT_MANAGER:UnregisterForEvent("QuestLurker", EVENT_ADD_ON_LOADED)
  17.         end
  18. end

Last edited by circonian : 10/27/14 at 05:11 AM.
  Reply With Quote
10/27/14, 04:48 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by circonian View Post
Here is what I see:

You have the wrong addon name in your register for event:
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("QuestLurkerZone", EVENT_ZONE_CHANGED, ZoneQuest)
  2.  
  3. -- The first parameter is supposed to be the name of your addon, which is QuestLurker so it should be this:
  4. EVENT_MANAGER:RegisterForEvent("QuestLurker", EVENT_ZONE_CHANGED, ZoneQuest)
The first argument is unique name for event handler (single event can't have two handlers with the same name). Handler name doesn't have to be addon name, you can use "QuestLurkerZone" or whatever else.

Originally Posted by circonian View Post
Lua Code:
  1. local function LoadSavedVars()
  2.     -- Always clear anchors before setting them
  3.     QuestLurker:ClearAnchors()
  4.    
  5.     -- You also need to specify what you are anchoring to, GuiRoot is the main window
  6.     QuestLurker:SetAnchor(QuestVars.SV.Quest.point, GuiRoot, QuestVars.SV.Quest.relPoint, QuestVars.SV.Quest.offsetx,QuestVars.SV.Quest.offsety)
  7. end
If you leave second argument (anchorTargetControl) nil, control will be automatically anchored to its parent - in this case to GuiRoot. There's no need to change code.


My comments:
  • Your code won't work in zones which are not in the quests table. You will get an error ".. is not supported for string .. nil". Either check if numQuest is not nil or use local numQuests = quests[zoneIndex] or "".
  • It could be a good idea to use zone index instead of zone name (because of localized zone names).
Example:
Lua Code:
  1. local quests ={
  2. --Aldmeri Dominion
  3.     [179] = 51, --Auridon
  4.     [295] = 11, --Khenarthi's Roost
  5.     [181] = 44, --Grahtwood
  6.     [19]  = 50, --Greenshade
  7.     [12]  = 45, --Malabal Tor
  8.     [180] = 60, --Reaper's March
  9.     [155] = 32, --Coldharbour
  10.  
  11.     --rest of the table
  12.     --Full list of zoneIndex codes is here: [url]http://www.esoui.com/forums/showpost.php?p=12693[/url]
  13. }
  14.  
  15. local function ZoneQuest()
  16.     local myZone = GetUnitZone("player")
  17.     local zoneIndex = GetCurrentMapZoneIndex()
  18.     local numQuests = quests[zoneIndex]
  19.     if numQuests ~= nil then
  20.         QuestLurkerQuest:SetText(myZone..": "..numQuests)
  21.         QuestLurker:SetHidden(false)
  22.     else
  23.         QuestLurker:SetHidden(true)
  24.     end
  25. end

Last edited by Garkin : 10/27/14 at 07:42 AM. Reason: Corrected, it is as Merlight says...
  Reply With Quote
10/27/14, 05:13 AM   #4
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I knew it had to be unique, but I also thought it had to be the addon name.
I didn't know if you left it nil it would use GuiRoot either.

I edited my post to remove those comments to avoid confusion.
Nice to know, thanks for the info.
  Reply With Quote
10/27/14, 06:10 AM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Garkin View Post
If you leave second argument (anchorTargetControl) nil, control will be automatically anchored to GuiRoot.
Control's parent, actually. Which in this case happens to be GuiRoot
  Reply With Quote
10/27/14, 07:43 AM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by merlight View Post
Control's parent, actually. Which in this case happens to be GuiRoot
You're right, I have corrected it in my answer.
  Reply With Quote
10/27/14, 03:40 PM   #7
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I cleaned up a lot of this code from looking at all your suggestions. Only thing I haven't done yet is used Garkins suggestion for the zone index. However I think I want to do this and this is going to take a while to get all zones in lol I think it showed near 400 something zones or more. I want to add something that can track a little better like in if you done all the quest in the area or not. If any suggestions let me know. I will probably need help with the code. However you all are making me a lot better at this. Thank you all for the info and help.
  Reply With Quote
10/27/14, 04:00 PM   #8
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
You can use achievements to check how many quests you have finished. You will need this function (copied from the documentation):

GetAchievementCriterion(achievementId, criterionIndex)
Returns: description, numCompleted, numRequired

Achievement is for example Auridon Adventurer, achievement ID 604 (number in url), this achievement has just one criteria, so criterionIndex will be 1 and you want to know how many quests you have already finished (numCompleted).
Lua Code:
  1. local _, numCompleted = GetAchievementCriterion(604, 1)
  2. d("You have finished " .. numCompleted .. " quests in Auridon.")

Last edited by Garkin : 10/27/14 at 04:03 PM.
  Reply With Quote
10/27/14, 04:21 PM   #9
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I'm trying to understand how that works. If the achievement is only 37 quest and there are 51 quest in Auridon wouldn't it just say your finished after you do 37 quest instead of the actual 51 quest?

If I use this I want it to be a constant reminder for the user of questlurker. Would I have to make another window like the current one that says the zone name and quest number in it.

I just finished adding the zone index you suggested Garkin. Thank you it seems to work a lot better when you go to areas that are not in the list. So now it's not poping an error every time someone goes to a place I haven't added yet.

Last edited by zireko : 10/27/14 at 05:53 PM.
  Reply With Quote
10/27/14, 05:47 PM   #10
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by zireko View Post
I'm trying to understand how that works. If the achievement is only 37 quest and there are 51 quest in Auridon wouldn't it just say your finished after you do 37 quest instead of the actual 51 quest?

Also if you could where do I find the achievementid like you said 604 was Auridon so how do I find that number for each achivment?
I'm not sure how it actually works, you will have to try it by yourself. But for example main quests have their own achievements, so they are not counted to the zone achievement.

Achievement IDs can be found:
- Esohead (I gave you link in previous post, number in URL is achievement ID)
- this post: http://www.esoui.com/forums/showthread.php?t=2117
- using the Zgoo addon (place mouse over achievement in Journal and type /zgoo mouse, in Zgoo window find table achievement and its key achievementId)
- using the script which can be run from addon code or from ZAM Notebook, something like this:

Lua Code:
  1. for i = 1, GetNumAchievementCategories() do
  2.     local _, numSubCategories, numAchievements = GetAchievementCategoryInfo(i)
  3.     for k = 1, numAchievements do
  4.         local achievementId = GetAchievementId(i, nil, k)
  5.         local name = GetAchievementInfo(achievementId)
  6.         d( ("%04d: %s"):format(achievementId, name) )
  7.     end
  8.     if numSubCategories > 0 then
  9.         for j = 1, numSubCategories do
  10.             local _, numAchievements = GetAchievementSubCategoryInfo(i, j)
  11.             for k = 1, numAchievements do
  12.                 local achievementId = GetAchievementId(i, j, k)
  13.                 local name = GetAchievementInfo(achievementId)
  14.                 d( ("%04d: %s"):format(achievementId, name) )
  15.             end
  16.         end
  17.     end
  18. end
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » My code is acting up


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off