Thread Tools Display Modes
Prev Previous Post   Next Post Next
04-14-11, 02:08 PM   #1
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
SetScript and loops

Hello!

I'm kind of into archaeology atm, and writing a small addon about it to make it more comfortable to me (watching TV while digging simplifies everything!).

I'm encountering a problem, when I want to make a "solve-button".

I got a window with a statusbar of the current project of every race, next to the artifact icon. I want to be able to click on that icon, if I got enough artifacts, but my SetScript don't works:

lua Code:
  1. PredatorArchy:RegisterEvent('PLAYER_ENTERING_WORLD')
  2. PredatorArchy:SetScript('OnEvent', function()
  3.     local i, raceName, raceTex
  4.  
  5.     local _, _, hasArch = GetProfessions()
  6.  
  7.     if ( hasArch ) then
  8.         -- Setting up the main frame
  9.         PredatorArchy:SetBackdrop( {
  10.                 bgFile = solidTex,
  11.                 edgeFile = borderTex,
  12.                 tile = false,
  13.                 edgeSize = 8,
  14.                 insets = { left = 4, right = 4, top = 4, bottom = 4 }
  15.         } )
  16.         PredatorArchy:SetBackdropColor(0, 0, 0, 0.7)
  17.         PredatorArchy:SetWidth(300)
  18.         PredatorArchy:SetHeight(40)
  19.         PredatorArchy:EnableMouse(true)
  20.         PredatorArchy:RegisterForDrag("LeftButton","RightButton")
  21.         PredatorArchy:SetMovable(true)
  22.         PredatorArchy:SetUserPlaced(true)
  23.         PredatorArchy:SetScript("OnDragStart", function(self) if IsAltKeyDown() then self:StartMoving() end end)
  24.         PredatorArchy:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  25.         PredatorArchy:SetPoint('CENTER')
  26.  
  27.         PredatorArchy.SkillRank = CreateFrame('StatusBar', nil, PredatorArchy)
  28.         PredatorArchy.SkillRank:SetPoint('TOPLEFT', 15, -10)
  29.         PredatorArchy.SkillRank:SetPoint('BOTTOMRIGHT', PredatorArchy, 'TOPRIGHT', -15, -30)
  30.         PredatorArchy.SkillRank:SetStatusBarTexture(barTex)
  31.         PredatorArchy.SkillRank:SetStatusBarColor(0, 0.7, 0)
  32.         PredatorArchy.SkillRank:RegisterEvent('ARTIFACT_COMPLETE')
  33.         PredatorArchy.SkillRank:SetScript('OnEvent', function()
  34.             core.UpdateSkill(hasArch)
  35.             core.UpdateArtifacts()
  36.         end)
  37.  
  38.         PredatorArchy.SkillRank.back = PredatorArchy.SkillRank:CreateTexture(nil, 'BACKGROUND')
  39.         PredatorArchy.SkillRank.back:SetAllPoints(PredatorArchy.SkillRank)
  40.         PredatorArchy.SkillRank.back:SetTexture(barTex)
  41.         PredatorArchy.SkillRank.back:SetVertexColor(0.3, 0.3, 0.3, 1)
  42.  
  43.         PredatorArchy.SkillRank.text = lib.CreateFontObject(PredatorArchy.SkillRank, 14, font)
  44.         PredatorArchy.SkillRank.text:SetPoint('CENTER', 0, 1)
  45.         PredatorArchy.SkillRank.text:SetText('INIT')
  46.         PredatorArchy.SkillRank.text:SetJustifyH('CENTER')
  47.  
  48.         PredatorArchy.List = {}
  49.         for i = 1, GetNumArchaeologyRaces() do
  50.             raceName, raceTex = GetArchaeologyRaceInfo(i)
  51.  
  52.             PredatorArchy.List[raceName] = {}
  53.             PredatorArchy.List[raceName].raceName = raceName
  54.             PredatorArchy.List[raceName].raceIcon = PredatorArchy:CreateTexture(nil, 'OVERLAY')
  55.             PredatorArchy.List[raceName].raceIcon:SetSize(36,36)
  56.             PredatorArchy.List[raceName].raceIcon:SetTexture(raceTex)
  57.             PredatorArchy.List[raceName].raceIcon:SetPoint('TOPLEFT', PredatorArchy.SkillRank, 'TOPLEFT', 0, -(i*25))
  58.  
  59.             PredatorArchy.List[raceName].artifactIcon = CreateFrame('Button', nil, PredatorArchy)
  60.             PredatorArchy.List[raceName].artifactIcon:SetSize(21, 21)
  61.             PredatorArchy.List[raceName].artifactIcon:SetPoint('RIGHT', PredatorArchy, 'RIGHT', -15, 0)
  62.             PredatorArchy.List[raceName].artifactIcon:SetPoint('TOP', PredatorArchy.List[raceName].raceIcon, 'TOP', 0, -1)
  63.             PredatorArchy.List[raceName].artifactIcon:SetScript('OnClick', function()
  64.                 lib.debugging(PredatorArchy.List[raceName].raceName)
  65.                 -- core.SolveArtifact(PredatorArchy.List[raceName].raceName)
  66.             end)
  67.  
  68.             PredatorArchy.List[raceName].progress = CreateFrame('StatusBar', nil, PredatorArchy)
  69.             PredatorArchy.List[raceName].progress:SetStatusBarTexture(barTex)
  70.             PredatorArchy.List[raceName].progress:SetPoint('TOPLEFT', PredatorArchy.List[raceName].raceIcon, 'TOPRIGHT', -10, -1)
  71.             PredatorArchy.List[raceName].progress:SetPoint('BOTTOM', PredatorArchy.List[raceName].raceIcon, 'TOP', 0, -22)
  72.             PredatorArchy.List[raceName].progress:SetPoint('RIGHT', PredatorArchy.List[raceName].artifactIcon, 'LEFT', -10, 0)
  73.             PredatorArchy.List[raceName].progress:SetMinMaxValues(0, 1)
  74.             PredatorArchy.List[raceName].progress:SetValue(0)
  75.  
  76.             PredatorArchy.List[raceName].progress.back = PredatorArchy.List[raceName].progress:CreateTexture(nil, 'BACKGROUND')
  77.             PredatorArchy.List[raceName].progress.back:SetAllPoints(PredatorArchy.List[raceName].progress)
  78.             PredatorArchy.List[raceName].progress.back:SetTexture(barTex)
  79.             PredatorArchy.List[raceName].progress.back:SetVertexColor(0.3, 0.3, 0.3, 1)
  80.  
  81.             PredatorArchy.List[raceName].progress.text = lib.CreateFontObject(PredatorArchy.List[raceName].progress, 14, font)
  82.             PredatorArchy.List[raceName].progress.text:SetPoint('LEFT', 10, 1)
  83.             PredatorArchy.List[raceName].progress.text:SetText('INIT')
  84.  
  85.             PredatorArchy:SetHeight(PredatorArchy:GetHeight()+26)
  86.         end
  87.  
  88.         PredatorArchy:UnregisterAllEvents()
  89.         PredatorArchy:RegisterEvent('CHAT_MSG_CURRENCY')
  90.         PredatorArchy:SetScript('OnEvent', core.UpdateArtifacts)
  91.  
  92.         core.UpdateSkill(hasArch)
  93.         core.UpdateArtifacts()
  94.     end
  95.  
  96. end)

Lines 63/64 are my problems: When I click the button, a chat message is displayed with the name of the "clicked" race, so is the plan at least.
I always get the name of the race, with the highest ID (on my german client, it's "Anderes", should be "others".

I'm kind of sure, this is related to setting the script-handler inside of that loop, which iterates all races, but on the other hand, it doesn't seem logic, because setting the right textures and stuff is working.

Can someone give me a hint please?
__________________
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » SetScript and loops


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