Thread Tools Display Modes
01-07-10, 02:26 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
set variable onclick.

Why does this not work? it says it wants an = near then for both lines.

Code:
xpBar:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
xpBar:SetScript('OnClick', function(self, button)
	if button == "LeftButton" then
		if GrimUIData.xpBarvar = xpLeft then
			GrimUIData.xpBarvar = xpTot 
		elseif GrimUIData.xpBarvar = xpTot then
			GrimUIData.xpBarvar = xpLeft
		end
	end
	
	if button == 'RightButton' then
	end
	
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 02:32 PM   #2
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Originally Posted by Grimsin View Post
Why does this not work? it says it wants an = near then for both lines.

Code:
xpBar:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
xpBar:SetScript('OnClick', function(self, button)
    if button == "LeftButton" then
        if GrimUIData.xpBarvar == xpLeft then
            GrimUIData.xpBarvar = xpTot 
        elseif GrimUIData.xpBarvar == xpTot then
            GrimUIData.xpBarvar = xpLeft
        end
    end
    
    if button == 'RightButton' then
    end
    
end)
Need two equal signs in conditionals, only one when assigning a variable.
  Reply With Quote
01-07-10, 02:35 PM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
duh. i feel stupid
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 02:57 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
hmm still having trouble with it. everything seems to be working except the click to change text format part. also does not seem to check if your a hunter or not proper. Shows the pet xp on all chars. of course thats prolly because its showing the first method in the onevent script for everyone.

Code:
local module = GrimUI:RegisterModule("ExpRepBar")

function module:OnInitialize()
	if not GrimUIData.xpBarvar then GrimUIData.xpBarvar = xpTot end
end


local frame = CreateFrame("Frame", nil, UIParent)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_XP_UPDATE")
frame:RegisterEvent("PLAYER_LEVEL_UP")
frame:RegisterEvent("UPDATE_EXHAUSTION")

GrimUI.frame = frame

local border = CreateFrame('Button', "xpBarClick", UIParent)
border:SetHeight(20)
border:SetWidth(220)
border:SetPoint("CENTER", UIParent, "CENTER", 0, 0)

local xpText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
xpText:SetPoint("CENTER", border, "CENTER", 0, 0)
xpText:SetTextColor(.9, .7, 1)
xpText:SetFont("Fonts\\FRIZQT__.TTF", 11, "nil")
frame.xpText = xpText

local xpBar = CreateFrame("StatusBar", nil, frame, "TextStatusBar")
xpBar:SetWidth(218)
xpBar:SetHeight(20)
xpBar:SetPoint("CENTER", border, "CENTER", 0, 0)
xpBar:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
xpBar:SetStatusBarColor(.5, 0, .75, 1)
xpBar:SetFrameLevel("1")

frame.xpBar = xpBar

local bg = xpBar:CreateTexture(nil, "BACKGROUND")
bg:SetTexture(0, 0, 0, .5)
bg:SetWidth(218)
bg:SetHeight(20)
bg:SetPoint("CENTER", border, "CENTER", 0, 0)



border:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
border:SetScript('OnClick', function(self, button)
	if button == "LeftButton" then
		if GrimUIData.xpBarvar == xpLeft then
			GrimUIData.xpBarvar = xpTot 
		elseif GrimUIData.xpBarvar == xpTot then
			GrimUIData.xpBarvar = xpLeft
		end
	end	
end)

frame:SetScript("OnEvent", function(self) 
	local currXP, nextXP = UnitXP("Player"), UnitXPMax("Player") 
	local leftXP = (nextXP - currXP)
	local myClass = UnitClass("player")
	
	local petXPcur, petXPnex = GetPetExperience();
	local petXPleft = (petXPnex - petXPcur)
	local restXP, percentXP = GetXPExhaustion(), floor(currXP / nextXP * 100) 
	local percentRestXP = floor(restXP / nextXP * 100)
	local str 
	if GrimUIData.xpBarvar == xpLeft and myClass == Hunter then 
		str = ("%s/%s (%s %s%%R) Pet %s/%s"):format(leftXP, nextXP, restXP, percentRestXP, petXPleft, petXPnex) 
	elseif GrimUIData.xpBarvar == xpLeft and myClass == not Hunter then
		str = ("%s/%s (%s %s%%R)"):format(leftXP, nextXP, restXP, percentRestXP)
	elseif GrimUIData.xpBarvar == xpTot	and myclass == Hunter then
		str = ("%s/%s (%s %s%%R) Pet %s/%s"):format(currXP, nextXP, restXP, percentRestXP, petXPcur, petXPnex)
	elseif GrimUIData.xpBarvar == xpTot and myclass == not Hunter then
		str = ("%s/%s (%s %s%%R)"):format(curXP, nextXP, restXP, percentRestXP)
	end
	
	xpText:SetText(str) 
	xpBar:SetMinMaxValues(min(0, currXP), nextXP) 
	xpBar:SetValue(currXP) 
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 03:13 PM   #5
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Add this to your OnClick to reinitialize when you toggle:
frame:GetScript("OnEvent")(frame)

Change your UnitClass line to this, so your script isn't broken on other locales:
local _, myClass = UnitClass("player")

Also, where you have Hunter, you need to be using "HUNTER" (need those quotes, Hunter is not assigned as a variable).
myClass ~= "HUNTER"
myClass == "HUNTER"

Last edited by Katae : 01-07-10 at 03:18 PM.
  Reply With Quote
01-07-10, 03:24 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Katae View Post
Add this to your OnClick to reinitialize when you toggle:
frame:GetScript("OnEvent")(frame)

Change your UnitClass line to this, so your script isn't broken on other locales:
local _, myClass = UnitClass("player")

Also, where you have Hunter, you need to be using "HUNTER" (need those quotes, Hunter is not assigned as a variable).
myClass ~= "HUNTER"
myClass == "HUNTER"
does hunter need to be caps?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 03:30 PM   #7
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
just noticed the ~= was that a typeo or?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 03:32 PM   #8
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Originally Posted by Grimsin View Post
does hunter need to be caps?
Yes, it's the localized class string, which is the same in all locales.

Originally Posted by Grimsin View Post
just noticed the ~= was that a typeo or?
~= means not equal to, the opposite of ==
  Reply With Quote
01-07-10, 03:49 PM   #9
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
so remove the not in there then. All is working except it does nothing when i click...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 03:50 PM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
maybe it has to do with the frame lvls? do i need to make the xpText overlay clickthrew?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 03:59 PM   #11
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Are you intending for xpTot/xpLeft to be variables? You don't define them anywhere, they're nil from what I can tell.

They should be "xpTot" and "xpLeft" if that's not the case...
  Reply With Quote
01-07-10, 04:06 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
well i changed the 2nd line to read, i thought that set it to xpTot at first, then clicking should change it. Those are supposed to be variables though...

Code:
function module:OnInitialize()
	if GrimUIData.xpBarvar == nil then 
	GrimUIData.xpBarvar = xpTot 
	end
end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 04:08 PM   #13
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
oh the function oninitialize its just a simple hook to a frame that fires on PLAYER_LOGIN.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 04:19 PM   #14
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Originally Posted by Grimsin View Post
well i changed the 2nd line to read, i thought that set it to xpTot at first, then clicking should change it. Those are supposed to be variables though...
So xpTot is set to something earlier in the file?
  Reply With Quote
01-07-10, 04:24 PM   #15
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
here is the full thing the first chunk is the grimUI core. so you can see what is going on or at lest what i have attempted to make go on... 2nd chunk is the xpbar file, all of it.

GrimUIcore.lua
Code:
GrimUI = {}
local mt_grimui = {__index = GrimUI}
local modules = {}
local defaults = {__index={}}
local dummy = function() end
GrimUI.Modules = modules
GrimUI.Dummy = dummy

local function RunSlashCmd(cmd)
  local slash, rest = cmd:match("^(%S+)%s*(.-)$")
  for name in pairs(SlashCmdList) do
     local i = 1
     local slashCmd
     repeat
        slashCmd = _G["SLASH_"..name..i]
        
        if slashCmd == slash then
           -- Call the handler
           SlashCmdList[name](rest)
           return true
        end
        i = i + 1
     until not slashCmd
  end
end

GrimUI.RunSlashCMD = RunSlashCmd

function GrimUI:RegisterModule(name)
	local module = setmetatable({}, mt_grimui)
	modules[name] = module
	return module
end

function GrimUI:GetModule(name)
	return modules[name]
end


function GrimUI:HideFrame(frame)
	if not frame then return end
	frame:Hide()
	frame.Show = dummy
end

function GrimUI:ShowFrame(frame)
	if not frame then return end
	frame.Show = nil
	frame:Show()
end

function GrimUI:LockFrame(frame)
	if not frame then return end
	frame.SetPoint = dummy
	frame.ClearAllPoints = dummy
end

function GrimUI:UnlockFrame(frame)
	if not frame then return end
	frame.SetPoint = nil
	frame.ClearAllPoints = nil
end

local reloadFrame
function GrimUI:OpenReloadFrame()
	if(reloadFrame) then
		return reloadFrame:Show()
	end

	reloadFrame = CreateFrame("Frame", nil, UIParent)
	reloadFrame:SetHeight(160)
	reloadFrame:SetWidth(350)
	reloadFrame:SetFrameStrata("HIGH") 
	reloadFrame:SetFrameLevel(5) 
	reloadFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
	reloadFrame:SetBackdrop{
		bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
		edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
		tile = true,
		tileSize = 32,
		edgeSize = 32,
		insets = {
			left = 11,
			right = 12,
			top = 12,
			bottom = 11
		}
	}

	local text = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
	text:SetText("GrimUI: Reload")
	text:SetPoint("TOP", 0, -20)

	local text2 = reloadFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
	text2:SetText("GrimUI requires a relog or ReloadUI\n to finish its configuration.")
	text2:SetPoint("TOP", 0, -60)

	local button = CreateFrame("Button", nil, reloadFrame, "UIPanelButtonTemplate")
	button:SetHeight(45)
	button:SetWidth(125)
	button:SetPoint("BOTTOMLEFT", 15, 15)
	button:SetText("Reload")
	button:RegisterForClicks("AnyUp")
	button:SetScript("OnClick", ReloadUI)

	local button2 = CreateFrame("Button", nil, reloadFrame, "UIPanelButtonTemplate")
	button2:SetHeight(45)
	button2:SetWidth(125)
	button2:SetPoint("BOTTOMRIGHT", -15, 15)
	button2:SetText("Cancel")
	button2:RegisterForClicks("AnyUp")
	button2:SetScript("OnClick", function() reloadFrame:Hide() end)
end

local eventFrame = CreateFrame("Frame", nil, UIParent)
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", function()
	if not GrimUIData then GrimUIData = {modsConfigured = {}} end
	GrimUI.Data = setmetatable(GrimUIData, defaults)

	for name, module in pairs(modules) do
		if module.OnFirstLoad and not GrimUIData.modsConfigured[name] then
			module:OnFirstLoad(GrimUIData)
			GrimUIData.modsConfigured[name] = true
		end
		if module.OnInitialize then
			module:OnInitialize()
		end
	end
end)
ExpRepBar.lua
Code:
local module = GrimUI:RegisterModule("ExpRepBar")

function module:OnInitialize()
	if GrimUIData.xpBarvar == nil then 
	GrimUIData.xpBarvar = xpTot 
	end
end


local frame = CreateFrame("Frame", nil, UIParent)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_XP_UPDATE")
frame:RegisterEvent("PLAYER_LEVEL_UP")
frame:RegisterEvent("UPDATE_EXHAUSTION")

GrimUI.frame = frame

local border = CreateFrame('Button', "xpBarClick", UIParent)
border:SetHeight(20)
border:SetWidth(220)
border:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
border:SetFrameStrata("HIGH")
border:SetFrameLevel("4")

local xpText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
xpText:SetPoint("CENTER", border, "CENTER", 0, 0)
xpText:SetTextColor(.9, .7, 1)
xpText:SetFont("Fonts\\FRIZQT__.TTF", 11, "nil")
frame.xpText = xpText

local xpBar = CreateFrame("StatusBar", nil, frame, "TextStatusBar")
xpBar:SetWidth(218)
xpBar:SetHeight(20)
xpBar:SetPoint("CENTER", border, "CENTER", 0, 0)
xpBar:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
xpBar:SetStatusBarColor(.5, 0, .75, 1)
xpBar:SetFrameLevel("1")

frame.xpBar = xpBar

local bg = xpBar:CreateTexture(nil, "BACKGROUND")
bg:SetTexture(0, 0, 0, .5)
bg:SetWidth(218)
bg:SetHeight(20)
bg:SetPoint("CENTER", border, "CENTER", 0, 0)

frame:SetScript("OnEvent", function(self) 
	local currXP, nextXP = UnitXP("Player"), UnitXPMax("Player") 
	local leftXP = (nextXP - currXP)
	local _, myClass = UnitClass("player")
	
	local petXPcur, petXPnex = GetPetExperience();
	local petXPleft = (petXPnex - petXPcur)
	local restXP, percentXP = GetXPExhaustion(), floor(currXP / nextXP * 100) 
	local percentRestXP = floor(restXP / nextXP * 100)
	local str 
	if GrimUIData.xpBarvar == xpLeft and myClass == "HUNTER" then 
		str = ("%s L (%s %s%%R) P %s"):format(leftXP, restXP, percentRestXP, petXPleft) 
	elseif GrimUIData.xpBarvar == xpLeft and myClass ~= "HUNTER" then
		str = ("%s L (%s %s%%R)"):format(leftXP, restXP, percentRestXP)
	elseif GrimUIData.xpBarvar == xpTot	and myclass == "HUNTER" then
		str = ("%s/%s (%s%%R) P %s/%s"):format(currXP, nextXP, percentRestXP, petXPcur, petXPnex)
	elseif GrimUIData.xpBarvar == xpTot and myclass ~= "HUNTER" then
		str = ("%s/%s (%s%%R)"):format(curXP, nextXP, percentRestXP)
	end
	
	xpText:SetText(str) 
	xpBar:SetMinMaxValues(min(0, currXP), nextXP) 
	xpBar:SetValue(currXP) 
end)

border:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
border:SetScript('OnClick', function(self, button)
	if button == "LeftButton" then
		if GrimUIData.xpBarvar == xpLeft then
			GrimUIData.xpBarvar = xpTot 
		elseif GrimUIData.xpBarvar == xpTot then
			GrimUIData.xpBarvar = xpLeft
		end
		frame:GetScript("OnEvent")(frame)
	end	
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 04:27 PM   #16
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
From your code it still looks like xpTot and xpLeft is nil.
  Reply With Quote
01-07-10, 04:57 PM   #17
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
ya cargor just showed me that... needed to have them in quotes to make them strings. also few typos but. got it working now on to how to make the whole thing turn into a reputation bar as well and give it right click menu functions.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 05:54 PM   #18
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Main things I immediately noticed which may be your clicking issue:

Code:
border:RegisterForClicks("LeftButtonUp", "RightButtonUp")
border:SetScript("OnClick", function(self, button)
There's more throughout. Double quotes (") mate, not single (').

  Reply With Quote
01-07-10, 05:57 PM   #19
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
hmm well it works with single quotes
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-07-10, 05:59 PM   #20
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
It doesn't matter if they're double or single.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » set variable onclick.


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