Jump to content




rightclicking menu? Removing only removes visuality, not functionality


  • You cannot reply to this topic
5 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 28 March 2014 - 09:56 PM

Hello there


Im working on a rightclick menu function which is used by:
mytbl={
  x=e[3];
  y=e[4];
  content = {
    {
      text="New"; --- text of the menu
      backgroundColor=colors.white; 
      textColor=colors.lime;
      func=true; -- what function it will run
    };
  };
}
setmetatable( mytbl, { __index = tbl } )
clickMenu = mytbl:menu()

My whole program is on Pastebin.com

or if you're bored:
Edit: just fixed the spoilers with code tags.
Spoiler



The result when running my function / program:

Whenever i rightclick the menu pops out fine.
When i click outside / someplace the menu disappears ( thats good ), BUT
then if i click on the X/Y choordinates of the menu, it still flashes .. I have no idea where this stupidity occours...

Could you please help?

Thanks in Advance

Edited by Mikk809h, 28 March 2014 - 09:59 PM.


#2 CometWolf

  • Members
  • 1,283 posts

Posted 28 March 2014 - 10:14 PM

Your clearing the local con variable rather than the actual table contents in your remove function.
				local con = self.content;
				con = nil
so clickMenu will always be ~= nil and it will thus call the init function regardless.
		if e[2] == 1 then
		  if clickMenu ~= nil then
				local resp = clickMenu.initialize( e[3], e[4] )
				clickMenu.remove()

it should instead be
				local con = self.content;
				self.content = nil

On second thought, clickMenu would probably still not be nil... Personally i prefer to use one main table for the functions, have the new tables inherit that table, then pass the table to those functions, rather than copying the functions themselves to the table. Makes stuff like this easier to deal with :P

Edited by CometWolf, 28 March 2014 - 10:29 PM.


#3 Goof

  • Members
  • 751 posts

Posted 28 March 2014 - 11:25 PM

Ohhh... yeah of course!!!

That solved everything ( just made some changes to the final(almost?) rightclick function with my customable menus :D/> Yay!

Spoiler

Thank you!

Edited by Mikk809h, 28 March 2014 - 11:25 PM.


#4 Goof

  • Members
  • 751 posts

Posted 29 March 2014 - 12:27 PM

Hello again

I've run into another problem;
After the menu appears, and i click outside it ( to get it disappear ), then it disappears fine,
but when i try to click/rightclick/mousewheelclick anywhere on the screen, it comes with an error:
test:115: Bad argument: Table expected, got nil

And my current code( on pastebin )


I thought that after i used the clickMenu.remove() it removes the whole variable/table "clickMenu", but it doesn't seem to...

Why?

Thanks in Advance

#5 CometWolf

  • Members
  • 1,283 posts

Posted 29 March 2014 - 12:48 PM

Simply calling clickMenu.remove in this code will only clear the table clickMenu.content, not clickMenu itself. However you seem to have added clickMenu = nil afterwards, which should be enough. The current problem is unrelated though.
You're only clearing the table if you actually click on an option.
	  if clickMenu ~= nil then
	    local resp = clickMenu.initialize( e[3], e[4] )
	    if resp == true then --remove this if statement
		  clickMenu.remove()
		  clickMenu = nil
	    end


#6 Goof

  • Members
  • 751 posts

Posted 29 March 2014 - 12:52 PM

Ehh... I still get an error, but its in the remove function...
(line 137 : bad argument: table expected, got nil )

Code


EDIT: Nevermind.. just forgot to remove the self.content = nil xD

Everything works like a charm

Thank you

Edited by Mikk809h, 29 March 2014 - 12:55 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users