• DMenu:Remove()
    9 replies, posted
Hi, I have created a DMenu with some submenus. Is there a way to remove a submenu once its created? exmaple submenu:Remove() I have tried using Remove(), Hide(), Close(), SetVisible(false) but these dont work. trying to remove this: DMenu/AddSubMenu Any help will be appreciated, thanks
Check the returns of DMenu:AddSubMenu.
surely doing submenu:Remove() will return the first value, Panel, and remove that? if not how can I select what return value i want to use, i tried submenu.panel:Remove() but got errors
Panel:Remove() doesn't return anything, it just removes the panel it was called on. To select specific return values of functions you'd do what I did in the code I provided. "submenu.panel:Remove()" would cause errors because submenu.panel is nil, the submenu is the panel you want to call the function on.
I didnt say Panel:Remove() returns a value, i said that the subpanel will return a value (probably its first one (panel)) then remove that panel. Sorry I completely missed the code you provided, i just clicked the link you send and looked at the return values, I will try this in the morning. Also why do I have to do local panel, label = menu:AddSubMenu(...) then remove the panel. Why cant i just do local panel = menu:AddSubMenu(...) then remove the panel? I will try the code, but I would also like it explained a bit more.
The code you provided didnt work for me, had no errors either.
The subpanel doesn't return a value, it is a value. DMenu:AddSubMenu returns two things: the subpanel that was created, and the item/label that was added to the original menu. You don't need to do "local a, b, c = f()" if you only want the first value, you could just do "local a = f()". I don't even know what you're trying to do, that code was just so you could get an idea of what you want to do. Submenus get recreated everytime you hover over the option on the original menu so if you want to stop the submenu from opening you should check the DMenu/DMenuOption code. This is the code that opens the submenu: garrysmod/dmenuoption.lua If you want to close a submenu you should call DMenu:CloseSubMenu(submenu).
What I want to do is create a menu, add some submenu's then depending on some conditions add some contents to the submenus, then check if the submenus have anything in them, if they dont remove them so they no longer show up because in my use case there is no reason to show the user the menu if there is nothing to use inside it. https://files.facepunch.com/forum/upload/111841/a56be876-0389-43d7-a7b7-fb261ab09fab/image.png My example above, i have a menu with ulx commands, it checks if the user can use the command then if they can it adds it to the submenu. I want to check if there are no commands in the submenu and remove it if there are not any. "if you only want the first value, you could just do "local a = f()" Isn't that what I was doing anyway? menu:CloseSubMenu(submenu) didn't do anything or at least not what i wanted it to do Just to clarify: I want admins to see this, https://files.facepunch.com/forum/upload/111841/13408479-fac7-4b45-a13f-354fa35cbc43/image.png and users to see this, https://files.facepunch.com/forum/upload/111841/c777cc40-bd9e-49cd-84da-9698ada2d603/image.png Without checking if there are an admin or not. I am already checking if they can use the command before I add it to the menu so there is no need to check if they are an admin. All I want to do is remove the submenus that have no contents. If this is possible, I would appreciate the help.
In that case you'll want to remove the DMenuOption (label) that was added instead of the DMenu (submenu).
This works, thank you soo much Also thank you for the suggestion with the extra white space
Sorry, you need to Log In to post a reply to this thread.