DMenu.AddOption

From GMod Wiki

Jump to: navigation, search
Function
Syntax DMenu:AddOption( String name,Function On-click function )
Description:
Adds an option to a DMenu.
Returns: DMenuOption
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=DMenu.AddOption]DMenu.AddOption [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionCreates a menu with options to print each players name.
Used onNewerClient.png
Code
 
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
 
local MenuButton = vgui.Create("DButton")
MenuButton:SetParent( DermaPanel )
MenuButton:SetText( "Menu >" )
MenuButton:SetPos(25, 50)
MenuButton:SetSize( 150, 175 )
function MenuButton:DoClick()
    local Menu = DermaMenu()
    for _,ply in pairs(player.GetAll()) do
        Menu:AddOption(ply:Name(),function() print(ply:Name()) end)
    end
    MenuButtonOptions:Open() -- Open the menu AFTER adding your options
end
 
OutputN/A
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox