Thread Tools Display Modes
04-06-09, 09:46 AM   #1
Geebles
A Murloc Raider
Join Date: Apr 2009
Posts: 8
Question Dropdown Checkbox won't uncheck

I'm trying toggle a drop-down menu checkbox, but isn't working. I've managed to get it to go from no check to being checked, but then it won't uncheck again visually.


the menu item...
Code:
menu2 = {};
menu2.text = "Movable";
menu2.func = function () MenuMoveClick(this); end
menu2.checked = vMovable;

the function...
Code:
function MenuMoveClick(obj)
	if(vMovable==1) then
		vMovable=0;
	else
		vMovable=1;
	end
end

Any idea why it won't un-check again?
  Reply With Quote
04-06-09, 10:11 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Is vMovable an upvalue, or is it re-defined every time your menu function is being called? If the latter, that would be causing the issue.

You can also simplify your MenuMoveClick() function as so:

Code:
local function MenuMoveClick()
        vMovable = not vMovable
end
...and then, in your menu function:

Code:
menu2.func = MenuMoveClick
This calls MenuMoveClick without defining a closure. I see no reason to be passing obj as an argument, since you are never checking the state of obj when toggling the vMovable value.

Also, for efficiency's sake, you should be re-using an upvalued table for every menu level. At the moment, you're making a new table for every menu every time your function is called - this will incur unnecessary garbage collection.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
04-06-09, 12:29 PM   #3
Geebles
A Murloc Raider
Join Date: Apr 2009
Posts: 8
I'm not sure what an 'upvalue' is

I tried those suggestions, but either messed it up or because I didn't post the whole code, it didn't work.
It did help me get it working though. I think the problem was not setting the variable vMovable at the beginning of the page (outside of the functions) so it wasn't being maintained.
  Reply With Quote
04-06-09, 04:29 PM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
That's an upvalue.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Dropdown Checkbox won't uncheck


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