• Clientside Script not executing?
    5 replies, posted
I have these scripts: cl_init.lua cl_mainmenu.lua init.lua shared.lua player.lua cl_init and cl_mainmenu are both clientside, and I want to have this code inside cl_mainmenu: [CODE] function mainMenu() local mainMenu = vgui.Create( "DFrame" ) mainMenu:SetSize( 620, 710 ) mainMenu:SetTitle( "Herb Roleplaying" ) mainMenu:SetVisible( true ) mainMenu:SetDraggable( false ) mainMenu:ShowCloseButton ( false ) mainMenu:MakePopup() mainMenu:Center() local PropertySheet = vgui.Create( "DPropertySheet" ) PropertySheet:SetParent( mainMenu ) PropertySheet:SetSize( 600, 640 ) PropertySheet:Center() -- Character Sheet local CharacterSheetBox = vgui.Create( "DPanel" , PropertySheet) CharacterSheetBox:SetPos( 25, 50 ) CharacterSheetBox:SetSize( 50, 50 ) CharacterSheetBox.Paint = function() -- Paint function surface.SetDrawColor( 50, 50, 50, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, CharacterSheetBox:GetWide(), CharacterSheetBox:GetTall() ) -- Draw the rect end -- Character Name local CharacterNameBox = vgui.Create( "DPanel" , CharacterSheetBox) CharacterNameBox:SetPos( 10, 10 ) CharacterNameBox:SetSize( 570, 30 ) CharacterNameBox.Paint = function() -- Paint function surface.SetDrawColor( 70, 70, 70, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, CharacterNameBox:GetWide(), CharacterNameBox:GetTall() ) -- Draw the rect end local CharacterNameLabel = vgui.Create( "Label", CharacterNameBox ) CharacterNameLabel:SetPos( 7, 8 ) CharacterNameLabel:SetText( "Character Name:" ) CharacterNameLabel:SizeToContents() local CharacterName = vgui.Create( "DTextEntry", CharacterNameBox ) CharacterName:SetPos( 120, 5 ) CharacterName:SetTall( 20 ) CharacterName:SetWide( 360 ) CharacterName:SetEnterAllowed( true ) local CharacterNameChange = vgui.Create( "DButton", CharacterNameBox) CharacterNameChange:SetText( "Change" ) CharacterNameChange:SetPos( 500, 5 ) CharacterNameChange:SetSize( 50,20 ) CharacterNameChange.DoClick = function() RunConsoleCommand( "kill" ) end -- Character Details local CharacterDetailBox = vgui.Create( "DPanel" , CharacterSheetBox) CharacterDetailBox:SetPos( 10, 45 ) CharacterDetailBox:SetSize( 570, 30 ) CharacterDetailBox.Paint = function() -- Paint function surface.SetDrawColor( 70, 70, 70, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, CharacterDetailBox:GetWide(), CharacterDetailBox:GetTall() ) -- Draw the rect end local CharacterDetailLabel = vgui.Create( "Label", CharacterDetailBox ) CharacterDetailLabel:SetPos( 7, 8 ) CharacterDetailLabel:SetText( "Character Details:" ) CharacterDetailLabel:SizeToContents() local CharacterDetail = vgui.Create( "DTextEntry", CharacterDetailBox ) CharacterDetail:SetPos( 120, 5 ) CharacterDetail:SetTall( 20 ) CharacterDetail:SetWide( 360 ) CharacterDetail:SetEnterAllowed( true ) local CharacterDetailChange = vgui.Create( "DButton", CharacterDetailBox) CharacterDetailChange:SetText( "Change" ) CharacterDetailChange:SetPos( 500, 5 ) CharacterDetailChange:SetSize( 50,20 ) CharacterDetailChange.DoClick = function() RunConsoleCommand( "kill" ) end -- Employment local JobsCategory = vgui.Create( "DCollapsibleCategory", CharacterSheetBox ) JobsCategory:SetPos( 10, 80 ) JobsCategory:SetSize( 570,300 ) JobsCategory:SetExpanded( 1 ) JobsCategory:SetLabel( "Employment" ) local CitizenBox = vgui.Create( "DPanel" , JobsCategory) CitizenBox:SetPos( 10, 30 ) CitizenBox:SetSize( 50, 50 ) CitizenBox.Paint = function() -- Paint function surface.SetDrawColor( 70, 70, 70, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel surface.DrawRect( 0, 0, CitizenBox:GetWide(), CitizenBox:GetTall() ) -- Draw the rect end PropertySheet:AddSheet( "Character", CharacterSheetBox, "gui/silkicons/user", false, false, "All general info on your character." ) PropertySheet:AddSheet( "Server Rules", test, "gui/silkicons/page", false, false, "The rules of the server." ) end usermessage.Hook("mainMenu", mainMenu) [/CODE] But for some reason the above code does not work in cl_mainmenu. It is supposed to be activated by [CODE] function GM:ShowHelp( ply ) -- This hook is called everytime F1 is pressed. umsg.Start( "mainMenu", ply ) -- Sending a message to the client. umsg.End() end --Ends function [/CODE] in init.lua, but this will not work. It only works if the code is in cl_init. If the code is in cl_mainmenu, it says unhandled exception for mainMenu. I am pretty sure that I imported everything correctly in init.lua: [CODE] AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "player.lua" ) AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "cl_mainmenu.lua" ) include('shared.lua') include('player.lua') [/CODE] Any help would be appreciated.
Are you including cl_mainmenu in cl_init?
Make sure to put in cl_init: [lua]include("cl_mainmenu.lua")[/lua]
Thanks guys, it worked. Now could somebody be so kind as to tell me why that needs to be there? from what I gathered, cl_init is the master script for all clientside scripts. Am I correct?
Yes, but you're not telling it to load the mainmenu file. It's the same as the init file, you have to include each file you want to run.
Okay, thanks again!
Sorry, you need to Log In to post a reply to this thread.