• How to "execute" a lua file
    7 replies, posted
I'm making a "DFrame" with 5 "DButtons" on it. I would like each button to execute a lua file that is specified by a directory path. any ideas? [EDITLINE]9:42 PM[/EDITLINE] By that i meant i will have another .lua, and when i push button 1, it opens that lua file. So if button 1 is meant to open a different derma menu, when i push button one it closes the original DFrame and opens the derma that Button 1 was meant to open. Might be a little confusing. sorry =X
include()
[lua] local MAIN = vgui.Create( "DFrame" ) -- Your DFrame. local BUTTON = vgui.Create( "DButton", MAIN ) -- Your button parented to the frame. function BUTTON:DoClick() -- Define the function that is run on click. MAIN:Close() -- Close the frame. RunConsoleCommand( "lua_openscript_cl", "directory/to/thefile.lua" ) -- The directory starts in lua so if it's in autorun/client you would do "autorun/client/file.lua" end [/lua]
[QUOTE=cheiftiger;21418536][lua] local MAIN = vgui.Create( "DFrame" ) -- Your DFrame. local BUTTON = vgui.Create( "DButton", MAIN ) -- Your button parented to the frame. function BUTTON:DoClick() -- Define the function that is run on click. MAIN:Close() -- Close the frame. RunConsoleCommand( "lua_openscript_cl", "directory/to/thefile.lua" ) -- The directory starts in lua so if it's in autorun/client you would do "autorun/client/file.lua" end [/lua][/QUOTE] One problem - lua_openscript_cl is blocked via RunConsoleCommand().
Yeah, the file is included...but [lua] Button1.DoClick = function() --Any command to execute the other file here? end [/lua]
[QUOTE=CombineGuru;21418560]One problem - lua_openscript_cl is blocked via RunConsoleCommand().[/QUOTE] Fuuuuu- [lua] local MAIN = vgui.Create( "DFrame" ) -- Your DFrame. local BUTTON = vgui.Create( "DButton", MAIN ) -- Your button parented to the frame. function BUTTON:DoClick() -- Define the function that is run on click. MAIN:Close() -- Close the frame. include( "directory/to/file.lua" ) -- The directory starts in lua so if it's in autorun/client you would do "autorun/client/file.lua" end [/lua]
You shouldn't be executing files like that. include() them at the beginning and then call a function from that file in your DoClick.
That's what i figured also [lua] button1.DoCLick = function() DFrame:Close() include( "directory" ) end [/lua]
Sorry, you need to Log In to post a reply to this thread.