Thread Tools Display Modes
09-02-15, 06:48 PM   #1
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Any way to fire function X(self) with self param. from function Y() without events?

I got frame with self.A = 1, self.B = 2 and so on... parameters.

In this frame i trigger function X(self) when PLAYER_ENTERING_WORLD.

Code:
<Frame>
	<Scripts>
		<OnLoad>
			self:RegisterEvent("PLAYER_ENTERING_WORLD")
			self.A = 1
			self.B = 2
		</OnLoad>
		<OnEvent>
			self:UnregisterEvent("PLAYER_ENTERING_WORLD")
			X(self)
		</OnEvent>
	</Scripts>
</Frame>
Lua Code:
  1. function X(self)
  2.     print(self.A, self.B...) -- output 1 and 2 and so on paraetrs...
  3. end

And i got function Y() that trigger when custom Button pressed.

Code:
<Button>
	<Scripts>
		<OnLoad>
			self.Z = true
		</OnLoad>
		<OnClick>
			Y()
		</OnClick>
	</Scripts>
</Button>
Lua Code:
  1. function Y()
  2.     if self.Z == true then
  3.         -- Then i want to trigger function X(self) with it's frame self.A = 1, self.B = 2... parameters
  4.     end
  5. end

What is want, is to trigger frame function X(self) with self.A = 1, self.B = 2 parameters with function Y() or after Button pressed.

Will appreciate your help.
  Reply With Quote
09-02-15, 09:09 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Using XML for your frames you will need to get the frame itself from the global table

Code:
local Xframe = _G["NameOfFrameX"]
X(xFrame)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-02-15, 11:49 PM   #3
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
I think, I explained my problem not good enough, and I still require a bit of your help please. I spend lots of hours learning lua and trying to figure out everything by my self, but no luck, just lots of lua errors.
I got this xml code:
Code:
<Frame name="MyFrame" hidden="true" parent="InterfaceOptionsFramePanelContainer">
	<CheckButton name="$parentCheckBoxOne" inherits="InterfaceOptionsCheckButtonTemplate">
		<Anchors>
			<Anchor>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnLoad>
				self:RegisterEvent("PLAYER_ENTERING_WORLD")
				self.panel = "GROUPS_AND_RAID_FINDER"
				self.name = "ParentCheckBox"
				self.root = true
			</OnLoad>
			<OnEvent>
				self:UnregisterEvent("PLAYER_ENTERING_WORLD")
				SetMyOptionsButtons(self)
			</OnEvent>
			<OnClick>
				ToggleMyOptions(self)
			</OnClick>
		</Scripts>
	</CheckButton>
	<CheckButton name="$parentCheckBoxTwo" inherits="InterfaceOptionsSmallCheckButtonTemplate">
		<Anchors>
			<Anchor>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnLoad>
				self:RegisterEvent("PLAYER_ENTERING_WORLD")
				self.variable = "variable"
				self.name = "ChildCheckBox"
				self.parent = "ParentCheckBox"
			</OnLoad>
			<OnEvent>
				self:UnregisterEvent("PLAYER_ENTERING_WORLD")
				SetMyOptionsButtons(self)
			</OnEvent>
			<OnClick>
				ToggleMyOptions(self)
			</OnClick>
		</Scripts>
	</CheckButton>
</Frame>
I got global variables ParentCheckBox = true/false and ChildCheckBox = true/false

A want to control second one (Disable/Enable) if first one is on or off. And i would like to make it for lots of checkboxes, so i don't want to hardcode every single checkbox.

function SetMyOptionsButtons(self) - this function on event check if self.name == true - then checkbox is checked, else it's unchecked, plus it checks if self.parent not nil and if it isn't then this function disable button if self.parent == false

function ToggleMyOptions(self) - just set self.name to true or false.

First i thought that i can somehow fire some Blizzard events, for example every time i toggle checkbox with self.root == true it fires event (cvar) and then register this event for ChildCheckBox. But i think it's not the right way to trigger cvar.

I search Blizard code, and found this function, but can't figure out how to implement it in to my case.

Lua Code:
  1. function BlizzardOptionsPanel_SetupDependentControl (dependency, control)
  2.     if ( not dependency ) then
  3.         return;
  4.     end
  5.    
  6.     assert(control);
  7.    
  8.     dependency.dependentControls = dependency.dependentControls or {};
  9.     tinsert(dependency.dependentControls, control);
  10.    
  11.     if ( control.type ~= CONTROLTYPE_DROPDOWN ) then
  12.         control.Disable = function (self) getmetatable(self).__index.Disable(self) _G[self:GetName().."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b) end;
  13.         control.Enable = function (self) getmetatable(self).__index.Enable(self) _G[self:GetName().."Text"]:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b) end;
  14.     else
  15.         control.Disable = function (self) UIDropDownMenu_DisableDropDown(self) end;
  16.         control.Enable = function (self) UIDropDownMenu_EnableDropDown(self) end;
  17.     end
  18. end


Conclusion:
I thought maybe it's possible somehow to trigger ChildCheckBox SetMyOptionsButtons(self) function every time i click (toggle) ParentCheckBox? If it's possible could your please help me with a little example or a few lines of code.

Edit:
Changed SetAdvancedInterfaceOptionsButtons(self) to SetMyOptionsButtons(self)

Last edited by Nikita S. Doroshenko : 09-04-15 at 12:59 AM.
  Reply With Quote
09-03-15, 10:25 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
You haven't mention SetAdvancedInterfaceOptionsButtons(self) anywhere in the code so I'm not sure where this comes into it.

Your XML creates two checkbuttons called MyFrameCheckBoxOne and MyFrameCheckBoxTwo.

Assuming you want to use this as a template and in this example MyFrameCheckBoxOne is your "parent" and you want a generic way to call ToggleMyOptions for MyFrameCheckBoxTwo every time the parent is clicked then:

Code:
<Frame name="MyFrame" hidden="true" parent="InterfaceOptionsFramePanelContainer" virtual="true">
	<CheckButton name="$parentCheckBoxOne" inherits="InterfaceOptionsCheckButtonTemplate">
		<Anchors>
			<Anchor>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnLoad>
				self:RegisterEvent("PLAYER_ENTERING_WORLD")
				self.panel = "GROUPS_AND_RAID_FINDER"
				self.name = "ParentCheckBox"
				self.root = true
			</OnLoad>
			<OnEvent>
				self:UnregisterEvent("PLAYER_ENTERING_WORLD")
				SetMyOptionsButtons(self)
			</OnEvent>
			<OnClick>
				ToggleMyOptions(self)
				ToggleMyOptions(_G[self:GetParent():GetName().."CheckBoxTwo"])
			</OnClick>
		</Scripts>
	</CheckButton>
	<CheckButton name="$parentCheckBoxTwo" inherits="InterfaceOptionsSmallCheckButtonTemplate">
		<Anchors>
			<Anchor>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnLoad>
				self:RegisterEvent("PLAYER_ENTERING_WORLD")
				self.variable = "variable"
				self.name = "ChildCheckBox"
				self.parent = "ParentCheckBox"
			</OnLoad>
			<OnEvent>
				self:UnregisterEvent("PLAYER_ENTERING_WORLD")
				SetMyOptionsButtons(self)
			</OnEvent>
			<OnClick>
				ToggleMyOptions(self)
			</OnClick>
		</Scripts>
	</CheckButton>
</Frame>
MyFrame is not a great name for a top level frame but I'm assuming it's just an example.

You can also do this all in lua and avoid creating a bunch of global functions and the headache of debugging xml.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-03-15 at 10:57 AM.
  Reply With Quote
09-03-15, 07:06 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Fizzlemizz View Post
Using XML for your frames you will need to get the frame itself from the global table

Code:
local Xframe = _G["NameOfFrameX"]
X(xFrame)
If your frame was created in XML, it has a global name (one of several reasons why I and others keep to Lua and away from XML). You don't need to look up the name of your frame in the global table - it's already a global reference to your frame.
__________________
"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
09-03-15, 08:53 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
There you go, learn something new every day, thank you Seerah.

Originally Posted by Seerah View Post
If your frame was created in XML, it has a global name (one of several reasons why I and others keep to Lua and away from XML). You don't need to look up the name of your frame in the global table - it's already a global reference to your frame.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-04-15, 12:50 AM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Seerah View Post
If your frame was created in XML, it has a global name (one of several reasons why I and others keep to Lua and away from XML).
You can create an anonymous frame in xml, it only has a name if you use the name attribute.
  Reply With Quote
09-04-15, 12:57 AM   #8
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Thank you! Very appreciate your help and advises, you saved my day. and special thanks to Fizzlemizz, idea with ToggleMyOptions(_G[self:GetParent():GetName().."CheckBoxTwo"]) works perfectly.
  Reply With Quote
09-04-15, 01:39 AM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
In the end we are talking about an XML template (virtual) where the "name" can't be derived until after it has been instanciated so all you can do in the XML is reference the "name" in the global table. Unles $parent can be unfolded (unpacked) in XML outside the name attribute.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-04-15 at 02:16 AM.
  Reply With Quote
09-04-15, 04:32 AM   #10
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Still, this all looks very messy for such an arbitrary thing.
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Any way to fire function X(self) with self param. from function Y() without events?


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