• Derma Panels why dont they accept localplayer
    15 replies, posted
when im doing like [code] local DermaText = vgui.Create( "DTextEntry", DermaPanel ) DermaText:SetPos( 350, 430) DermaText:SetTall( 20 ) DermaText:SetWide( 450 ) DermaText:SetEnterAllowed( true ) DermaText.OnEnter = function() Msg("You entered -".. DermaText:GetValue( LocalPlayer:SetNWInt("username") ) .."-!" ) -- What happens when you press enter end [/code]
Probably because you're doing like a function without arguments/parameters.
So i do? [code] local DermaText = vgui.Create( "DTextEntry", DermaPanel ) DermaText:SetPos( 350, 430) DermaText:SetTall( 20 ) DermaText:SetWide( 450 ) DermaText:SetEnterAllowed( true ) DermaText.OnEnter = function(ply) Msg("You entered -".. DermaText:GetValue( ply:SetNWInt("username") ) .."-!" ) -- What happens when you press enter end [/code]
It's a function, not a variable. Add parentheses to the end.
now its saying [ERROR] gamemodes/wog/gamemode/cl_init.lua:148: attempt to call method 'SetNWInt' (a nil value) 1. OnEnter - gamemodes/wog/gamemode/cl_init.lua:148 2. unknown - lua/vgui/dtextentry.lua:103 so whats going on? and how do i make it check for the text then SetNWInt?
Ply is nil, thats what.
so i make in front of all the code [code] function registion() local ply = LocalPlayer() --code code code ^.^ end [/code] [editline]18th January 2014[/editline] nope that didn't work...
What are the errors, if any
[ERROR] gamemodes/wog/gamemode/cl_init.lua:134: attempt to call method 'SetNWInt' (a nil value) 1. OnEnter - gamemodes/wog/gamemode/cl_init.lua:134 2. unknown - lua/vgui/dtextentry.lua:103 [ERROR] gamemodes/wog/gamemode/cl_init.lua:149: attempt to call method 'SetNWInt' (a nil value) 1. OnEnter - gamemodes/wog/gamemode/cl_init.lua:149 2. unknown - lua/vgui/dtextentry.lua:103
[lua] DermaText.OnEnter = function() Msg("You entered -".. DermaText:GetValue()..", "..LocalPlayer():GetNWInt("username") .."-!" ) end [/lua] [Lua] DermaText.OnEnter = function() Msg("You entered -".. DermaText:GetValue()..".") LocalPlayer():SetNWInt("username", DermaText:GetValue ()) end [/lua] I'm not to sure what you're trying to do. So I took my guess at what you were trying. The first gets the value from the box and displays it with the users networked "username". The second sets the user's networked username as the value that was entered.
You can't change networked variables from the client and that's what you're trying to do.
yes im trying to network variables from the derma panel can that be done or no? or should i make a derma.lua in the my gamemode? in stand of cl_init.lua?
You can only use derma on the client, and the server can only change networked variables. Therefore you must send a message to the server from the client telling it what to do/change, basically what Matt was getting at. Here's an example. [url]http://wiki.garrysmod.com/page/net/SendToServer[/url]
Should be something like this. In your server side. [LUA] util.AddNetworkString("cl_usernameString") // Whatever you wanna call it. [/LUA] And in your client - Make sure those network string has the same name. [LUA] DermaText.OnEnter = function() Msg("You entered -".. DermaText:GetValue()..".") net.Start("cl_usernameString") net.WriteString(DermaText:GetValue()) net.SendToServer() end [/LUA]
oh i see so put net stuff i really need to learn net stuff better
Sorry, you need to Log In to post a reply to this thread.