• attempt to call method 'DoClick' (a nil value)
    2 replies, posted
Hello. So I am new to coding Lua and i was working on an entity with derma where if you use the entity you would get a derma popup asking if you would like to purchase with yes and no buttons. Anyway so i have set it up but i get a script error when i click yes on my derma panel. [CODE] [ERROR] lua/vgui/dlabel.lua:218: attempt to call method 'DoClick' (a nil value) 1. unknown - lua/vgui/dlabel.lua:218 [/CODE] And here are my clientside and server lua files init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/Items/ammocrate_grenade.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end end function ENT:Use(activator,caller) self:SetUseType(SIMPLE_USE) umsg.Start("DrawShopMenu", activator) umsg.Short("1") umsg.End() end util.AddNetworkString("buttonpress1") net.Receive("buttonpress1", buttonpress1) function buttonpress1() print ("hello!") end[/CODE] cl_init.lua [CODE]include("shared.lua") function ENT:Draw() self:DrawModel() end function DrawShopMenu() local frame = vgui.Create("DFrame") frame:SetSize(400, 100) frame:Center() frame:SetTitle('Armor Shop') frame:ShowCloseButton(true) frame:SetSizable(false) frame:SetDeleteOnClose(true) frame:MakePopup() local button = vgui.Create("DButton",frame) button:SetPos (10,55) button:SetSize(100,40) button:SetText("Yes") button.DoClick = buttonpress1() net.Start("buttonpress1") net.SendToServer() local button2 = vgui.Create("DButton",frame) button2:SetPos (290,55) button2:SetSize(100,40) button2:SetText("No") local label = vgui.Create("DLabel",frame) label:SetPos(120,30) label:SetText("Would you like to purchase armor?") label:SetSize(165,16) end usermessage.Hook("DrawShopMenu",DrawShopMenu) [/CODE]
You're trying to call a serverside function on the client. Do this instead: [lua] button.DoClick = function() net.Start("buttonpress1") net.SendToServer() end [/lua]
thankyou a buttload, i was watching a video on derma and looking at posts and it thought that where function() was i was suppose to put a certain function in its place. Just a stupid mistake that i spent way too long trying to fix. Thanks again
Sorry, you need to Log In to post a reply to this thread.