Page 1 of 3

lua & xml

PostPosted: Sat Jan 02, 2016 11:19 am
by cyklon
need some help creating a frame and if i understand things correct i must create the frame in xml and call for the frame in lua.

there is something im missing in the code but i dont know what it is..

*.lua coding
Code: Select all
local f = CreateFrame("customframe",nil,UIParent)
   f:SetFrameStrata("BACKGROUND")
   f:SetWidth(128)
   f:SetHeight(64)

local t = f:CreateTexture(nil,"BACKGROUND")
   t:SetTexture("blablabla.tga")
   t:SetAllPoints(f)
   f.texture = t

   f:SetPoint("CENTER",0,0)
   f:Show()
end


*.xml coding
Code: Select all
<Ui xmlns="http://www.blizzard.com/wow/ui/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Script File="luapath.lua"/>
<Frame name="customframe">
  <Anchors>
    <Anchor point="CENTER"/>
  </Anchors>
  <Frames>
    <Frame name="customframe">
      <Anchors>
        <Anchor point="CENTER"/>
      </Anchors>
    </Frame>
  </Frames>
</Frame>
 </Ui>

Re: lua & xml

PostPosted: Sat Jan 02, 2016 11:23 am
by Mimma
What error are you getting?

Re: lua & xml

PostPosted: Sat Jan 02, 2016 11:34 am
by modernist
you can use actually xml or lua to create a frame, and in this case you are actually doing the same creation job twice — overwriting whichever of the first you load by reusing the same name across your two files.

I personally find pure lua implementation to be a much cleaner and more effective method with less overhead, so I'd recommend:

Code: Select all
local f = CreateFrame("customframe", nil, UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(128)
f:SetHeight(64)
f:SetPoint("CENTER", 0, 0)
f:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]]})
f:SetBackdropColor(0, 0, 0, 1)

local t = f:CreateTexture(nil,"BACKGROUND")
t:SetTexture("blablabla.tga")
t:SetAllPoints()
f.texture = t


no need to call Show() as that is the default state on a frames creation. you can also call SetAllPoints() without an argument focus like this, and it'll default to the point references of the childs parent.

finally — you've not created a function or any kind of scoping, so no need to drop an 'end' at the foot of your file. that'll actually cause a lua error and is probably the reason your frame isn't showing up. i'd recommend turning on 'show lua errors' in your interface options if its currently toggled off.

someone else can probably give you a better overview of xml usage.

e: also note that custom textures have some rules that need to be followed — the most important of which is that the image must be saved at a size that is a power of 2 (2px, 4px, 8px, 16px, 32px, 64px, 128px etc.). i've taken the liberty of adding two more lines that add a simple backdrop to the frame (similar to that applied to tooltips or other blizzard elements), which will show up if the frame is created but your texture fails to successfully appear, for bug testing. you can remove those lines again once it is sorted.

Re: lua & xml

PostPosted: Sat Jan 02, 2016 11:49 am
by cyklon
That was quick replys, thanks, ill stick to lua then,, much easier to understand IMO :)

Re: lua & xml

PostPosted: Sat Jan 02, 2016 1:08 pm
by Geigerkind
It really depends what you want to achieve in the end:
If you just want a frame that handles events, a frame that is created by lua is perfect for the job whereas if you want to create a whole interface, xml might be the better choice for you.

This is such an interface for example:
Image

Re: lua & xml

PostPosted: Sat Jan 02, 2016 1:28 pm
by cyklon
i'm creating a frame(s) that will servs as an anchor for diffrent addons, now i just have to figure how to show the frames by typing a command and hiding them again by using a command again.

Re: lua & xml

PostPosted: Sat Jan 02, 2016 1:54 pm
by Geigerkind

Re: lua & xml

PostPosted: Sat Jan 02, 2016 1:58 pm
by cyklon
heheh,, ye, i found it earlier and trying to figure it out :) THANKS!

Re: lua & xml

PostPosted: Sat Jan 02, 2016 2:11 pm
by modernist
cyklon wrote:i'm creating a frame(s) that will servs as an anchor for diffrent addons, now i just have to figure how to show the frames by typing a command and hiding them again by using a command again.


Code: Select all
SLASH_ADDON1 = '/addon'
SlashCmdList['ADDON'] = function(arg)
    if f:IsShown() then f:Hide() else f:Show() end
end

Re: lua & xml

PostPosted: Sat Jan 02, 2016 2:13 pm
by cyklon
LOVE YOU! Thanks