Thread Tools Display Modes
10-30-11, 01:39 PM   #1
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Help creating swingtimer!

Hello guys! Currently using my own version of Mono's oUF layout. From looking at his other modules, I tried adding a swingtimer myself.

So basically, I have imported the oUF_swings into the embeds folder. After this I went to the lib.lua file, and played around with the code. After looking at the other modules, I made a script through the example from oUF_swing.
This is what I came up with;

lib.gen_Swing = function(f)
local Swing = CreateFrame("Frame", nil, self)
Swing:SetWidth(400)
Swing:SetHeight(20)
Swing:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 200)
Swing.texture = [=[Interface\TargetingFrame\UI-StatusBar]=]
Swing.color = {1, 0, 0, 0.8}
Swing.textureBG = [=[Interface\TargetingFrame\UI-StatusBar]=]
Swing.colorBG = {0, 0, 0, 0.8}
end

Now, can somebody tell me why it doesnt work? Any answers or guidelines would be really appreciated. Basically, no swingtimer is showing up on my screen in or out of combat.
  Reply With Quote
10-30-11, 03:44 PM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Without knowing anything about oUF_swings: It looks like you aren't assigning it to the oUF object.

Basically:
f.Swing = Swing

Look at the plug-ins requirement to figure out what the key name should be.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
10-30-11, 04:48 PM   #3
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Thanks for your reply, Haste! I am not too familiar with LUA yet, so I am not entirely sure of what you're speaking of.

However, seeing your comment, I recreated the script in a different way. I feel like I'm maybe closer to getting it right now.

lib.gen_swingtimer = function(f)
local Swing = s:CreateFrame("Frame", nil, f)
swing.SetPoint("center", 0, 200)
swing.SetHeigh(20)
swing.SetWidth(200)
swing:SetStatusBarTexture(cfg.statusbar_texture)
swing:GetStatusBarTexture():SetHorizTile(false)
swing:SetStatusBarColor(0.3, 0.5, 0.2)

swing.disableMelee = false
swing.DisableRanged = false
swing.hideOoc = true

f.swingtimer = swing
end

and then I added lib.gen_swingtimer(self) to the core.lua.
However, what happens now is that the oUF layout is not even showing up. Any chance you could help me a bit further?
  Reply With Quote
10-31-11, 12:42 AM   #4
Rostok
A Flamescale Wyrmkin
Join Date: Jul 2008
Posts: 127
Lua is case sensitive, so swing is not the same thing as Swing.

lib.gen_swingtimer = function(f)
local swing = s:CreateFrame("Frame", nil, f)
swing.SetPoint("center", 0, 200)
swing.SetHeigh(20)
swing.SetWidth(200)
swing:SetStatusBarTexture(cfg.statusbar_texture)
swing:GetStatusBarTexture():SetHorizTile(false)
swing:SetStatusBarColor(0.3, 0.5, 0.2)

swing.disableMelee = false
swing.DisableRanged = false
swing.hideOoc = true

f.Swing = swing
end
  Reply With Quote
10-31-11, 10:08 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
You should turn on Lua errors.
Lua Code:
  1. lib.gen_swingtimer = function(f)
  2.    local Swing = s:CreateFrame("Frame", nil, f)
  3.    swing.SetPoint("center", 0, 200)
  4.    swing.SetHeigh(20)
  5.    swing.SetWidth(200)
  6.    swing:SetStatusBarTexture(cfg.statusbar_texture)
  7.    swing:GetStatusBarTexture():SetHorizTile(false)
  8.    swing:SetStatusBarColor(0.3, 0.5, 0.2)
  9.  
  10.    swing.disableMelee = false
  11.    swing.DisableRanged = false
  12.    swing.hideOoc = true
  13.  
  14.    f.swingtimer = swing
  15. end

Line #1 will pop an error, as you are trying to index a nil global.
Line #14 should be f.Swing = swing as mentioned earlier.

Fixing those two issues should solve it.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
10-31-11, 07:30 PM   #6
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Hey again both of you! Thanks for both of your replies. And sorry for sounding like a dumbass, but I'm newly introduced to oUF, so I'm still learning. Now, I think I got some meaning out from your reply. I do not have access to my gamingcomputer right now, so can't test if it works. But are you implying that the code should look something like this?

forgot to add first line btw!

if(IsAddOnLoaded("oUF_Swing")) then
self.swing = s:CreateFrame("Statusbar", nil, self)
self.swing:SetPoint("CENTE", "UIParent", "CENTER", 0, 200)
self.swing:SetHeigh(20)
self.swing:SetWidth(200)
self.swing:SetStatusBarTexture(cfg.statusbar_texture)
self.swing:GetStatusBarTexture():SetHorizTile(false)
self.swing:SetStatusBarColor(0.3, 0.5, 0.2)

self.swing.disableMelee = false
self.swing.DisableRanged = false
self.swing.hideOoc = true

self.swing = swing
end
  Reply With Quote
10-31-11, 11:43 PM   #7
Ekaterina
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 65
Wink

The API documentation from ouf Swing:

Code:
--[[
	Elements handled:
	 .Swing [frame]
	 .Swing.Text [fontstring]
	 .Swing.TextMH [fontstring]
	 .Swing.TextOH [fontstring]
		
	Code Example:
	 .Swing = CreateFrame("Frame", nil, self)
	 .Swing:SetWidth(400)
	 .Swing:SetHeight(20)
	 .Swing:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 100)
	 .Swing.texture = [=[Interface\TargetingFrame\UI-StatusBar]=]
	 .Swing.color = {1, 0, 0, 0.8}
	 .Swing.textureBG = [=[Interface\TargetingFrame\UI-StatusBar]=]
	 .Swing.colorBG = {0, 0, 0, 0.8}
	 
	Autocreated if not created by Layout:
	 - .Twohand [statusbar]
	 - .Mainhand [statusbar]
	 - .Offhand [statusbar]
	 
	Shared:
	 - disableMelee [boolean]
	 - disableRanged [boolean]
	 - hideOoc [boolean] (Autohide on leaving Combat)

	Functions that can be overridden from within a layout:
	 - .OverrideText(text, now)
--]]
Try something like below - (Not tested!)
Code:
if(IsAddOnLoaded("oUF_Swing")) then 
	self.Swing = CreateFrame("Frame", nil, self)
 	self.Swing:SetPoint("CENTE", "UIParent", "CENTER", 0, 200)
 	self.Swing:SetHeigh(20)
 	self.Swing:SetWidth(200)
	self.Swing:SetStatusBarTexture(cfg.statusbar_texture)
 	self.Swing:GetStatusBarTexture():SetHorizTile(false)
 	self.Swing:SetStatusBarColor(0.3, 0.5, 0.2) 

	self.Swing.disableMelee = false
	self.Swing.DisableRanged = false
	self.Swing.hideOoc = true
 
 end
As Rostok pointed out, LUA is case sensitive so you do need to be careful of your capitalisations.

Also this:
self.swing = swing
, would be incorrect with your code for a couple of reasons.
  1. "self.swing" is the incorrect capitalisation of the ouf element. The correct version is self.Swing. As you had it throughout your code might throw errors and wouldn't work as expected.
  1. The 'swing' after your equals is a nil global. You haven't defined it anywhere(that I can see in the code you've provided).
  1. That line is unnecessary. When you do this:
    Code:
    self.Swing = CreateFrame("Frame", nil, self)
    you are creating the frame and assigning it directly to the ouf Swing element.
    If you had written the code like this:
    Code:
    	local s = CreateFrame("Frame", nil, self)
     	s:SetWidth(400)
     	s:SetHeight(20)
    	s:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 200)
    -- etc, etc
    then you would require the self.Swing = s, because you've created the frame, manipulated it, and then are handing it off to the ouf Swing element.

I hope that works and hasn't confused you further.
  Reply With Quote
11-01-11, 05:22 PM   #8
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Thank you again for replying! It looks like I have gotten a little better understanding of how the code should be implemented. Do not have access to my gaming computer atm, so I'm not able to test any codes yet.

However, thanks for all replies until now, they have all been helpful! I will try to play more with the code and use the info you provided below, and see if I manage to get my swingtimer up and running.
  Reply With Quote
11-02-11, 10:08 AM   #9
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Again in need of some help! I changed the code to how it should look, thanks to the comments above. From my understanding the code should be working right now.

However, one of the things I didn't get where the attempt to call a nil global thingy. And this is exactly the lua error I get.

lib.lua:168: attempt to index global 'self' (a nil value)
Where line 168 is the createframe line.

Could anybody help me more ?
  Reply With Quote
11-02-11, 12:43 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Post the whole file.
  Reply With Quote
11-02-11, 01:08 PM   #11
Aszeon
A Murloc Raider
Join Date: Mar 2010
Posts: 6
Whole file? As in my code, the whole lua error, the ouf_swing file, or my whole lib file ?
  Reply With Quote
11-02-11, 08:24 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, presumably the code of the oUF_Swing plugin is not the problem, nor is any code in oUF, since those things are being used successfully by dozens of other layouts, so it seems fairly obvious that we would want to see your code in order to tell you why your code is triggering an error message...

Also, please use [code] tags around your code snippets to preserve indentation, or use a paste service (eg. paste.wowace.com) and just post the link to the paste if your code is more than ~25 lines.
  Reply With Quote
11-03-11, 11:06 AM   #13
Monolit
A Black Drake
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 81
Originally Posted by Aszeon View Post
Again in need of some help! I changed the code to how it should look, thanks to the comments above. From my understanding the code should be working right now.

However, one of the things I didn't get where the attempt to call a nil global thingy. And this is exactly the lua error I get.

lib.lua:168: attempt to index global 'self' (a nil value)
Where line 168 is the createframe line.

Could anybody help me more ?
well, assuming you used code (as in copy-pasted) from Ekaterina's post in your function "lib.gen_swingtimer = function(f)" it's no surprise that you get that error.

speaking in simple words: your "self" in this case should be "f" or vice versa.

I guess it's worth a note that you have to call that function for appropriate element in core.lua presuming you did not change the general structure of my layout.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Help creating swingtimer!


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