Making VGUI with line editable by player and send that to serverside

Hi !
Sorry by advance but i have a problem : I’m beginner and i created a DFrame (lines below) but i would like to know how create lines which player can change the text… After the player has the text, he click (DoClick on a DButton) and the text is saved in a net (i think we must use net.SendToServer()).

The DFrame :

I have two problems :
1- What is the DXXXX to have a line the player can change ? I tried DLabelEditable but i don’t know how use it and there is the second problem:
2- How send to server and use this text to save in serverside and re-load in clientside in an other DFrame ?

And an other question, how manage there is a dropdown with all nick of players in the server in a DXXXXX ?

Thanks in advance (and sorry i begin) !
Regards,

1 - You could use a DTextEntry for that
2 - Depends what you’re trying to do exactly…

[editline]21st February 2016[/editline]

What are you trying to do with this that needs something sent to the server for it to work?

Take a look at the examples and adapt them to your needs.

[editline]21st February 2016[/editline]

And DTextEntry would be a viable way to get input from the user to send off.

Thanks, DText Entry works perfectly!
I explain (I think you understand with my lines below) : I would like to manage a player writes a texr (with DTextEntry), and in an other DFrame we can see the text the player wrote… Just simple.
I tried :



local reason
local ReasonTextEntry = vgui.Create( "DTextEntry", DermaCreateSuit )
				ReasonTextEntry:SetPos( 150, 100 )
				ReasonTextEntry:SetSize( 400, 100 )
				ReasonTextEntry:SetText( "" )

local ButtonFinished = vgui.Create("DButton", DermaCreateSuit)
		ButtonFinished:SetText( "CREATE" )
		ButtonFinished:SetPos( 225, 420 )
		ButtonFinished:SetSize( 100, 50 )
		ButtonFinished:SetFont( "computerFont" )
		ButtonFinished:SetTextColor( Color( 255, 0, 0, 255 ) )
		ButtonFinished.Paint = function( self )
		surface.SetDrawColor(50, 50, 50, 255)
		surface.DrawOutlinedRect(0, 0, self:GetWide(), self:GetTall())
		end
		ButtonFinished.DoClick = function()
    	DermaCreateSuit:Hide()
    	OpenMenuComputer = false
    	LocalPlayer():ChatPrint( "Your police report has been created !")
    	reason = ReasonTextEntry:GetValue()
		end

local ReasonTextEntry2 = vgui.Create( "DTextEntry", DermaSearchSuit )
					ReasonTextEntry2:SetPos( 150, 100 )
					ReasonTextEntry2:SetSize( 400, 100 )
					ReasonTextEntry2:SetText( reason )


But i have this error :

[ERROR] addons/xxxx/lua/entities/xxxx/cl_init.lua:227: bad argument #1 to ‘SetText’ (string expected, got nil)

I tried ReasonTextEntry2:SetText( ReasonTextEntry:GetValue() ) but doesn’t work…
I think this is not getvalue or there is a problem, but in my other DFrame there is no the text as the first… Please help me…
If I asked you for the serverside, this is because maybe i must use net to send the string at the server and re-send at the client but :
1- No interest / 2- If this is just client, i don’t have to send client…

To summarize, I just want to find the function that will allow me to have the entered text in an other DFrame… (I am not blocked as for DTextEntry but also for DListView and the GetSelectedLine but it’s the same principle so if you help me a little bit I would appreciate it and I think I understand).

Thanks by advance!

Please help… I search but not found…

Try running



DermaCreateSuit:Hide()


AFTER setting the variable as the DTextEntry’s text… whatever Hide is meant to do to whatever panel you’re doing it on could be removing the panel entirely, therefore making the text obviously nil

Thanks for help! But i’ve the same problem, i can’t put a variable in a SetText and i have this error :

[ERROR] addons/xxxx/lua/entities/xxxx/cl_init.lua:230: bad argument #1 to ‘SetText’ (string expected, got nil)

  1. SetText - [C]:-1
  2. unknown - addons/xxxx/lua/entities/xxxx/cl_init.lua:230
    3. unknown - lua/includes/modules/concommand.lua:54

Your variable [lua]local reason[/lua] is not defined and therefore nil. And ReasonTextEntry2:SetText( reason ) expects reason to be a string and not nil. You will have to add ReasonTexEntry2 before ButtonFinished. And modify your DoClick hook like this:

[lua]
ButtonFinished.DoClick = function()
DermaCreateSuit:Hide()
OpenMenuComputer = false
LocalPlayer():ChatPrint( “Your police report has been created !”)
reason = ReasonTextEntry:GetValue()
ReasonTextEntry2:SetText( reason )
end
[/lua]

EDIT:
Your code makes no sense at all to be honest. Why are there 2 text entries that do exactly the same? and why does the button set the text to the tex that has already been entered?

I summarize :



local reason = "Default"
local ReasonTextEntry = vgui.Create( "DTextEntry", DermaCreateSuit )
ReasonTextEntry:SetPos( 150, 100 )
ReasonTextEntry:SetSize( 400, 100 )
ReasonTextEntry:SetText( "" )

local ReasonTextEntry2 = vgui.Create( "DTextEntry", DermaSearchSuit )
ReasonTextEntry2:SetPos( 150, 100 )
ReasonTextEntry2:SetSize( 400, 100 )

local ButtonFinished = vgui.Create("DButton", DermaCreateSuit)
		ButtonFinished:SetText( "CREATE" )
		ButtonFinished:SetPos( 225, 420 )
		ButtonFinished:SetSize( 100, 50 )
		ButtonFinished:SetFont( "computerFont" )
		ButtonFinished:SetTextColor( Color( 255, 0, 0, 255 ) )
		ButtonFinished.Paint = function( self )
		surface.SetDrawColor(50, 50, 50, 255)
		surface.DrawOutlinedRect(0, 0, self:GetWide(), self:GetTall())
		end
		ButtonFinished.DoClick = function()
		reason = ReasonTextEntry:GetValue()
		ReasonTextEntry2:SetText( reason )
    	DermaCreateSuit:Hide()
    	OpenMenuComputer = false
    	LocalPlayer():ChatPrint( "Your police report has been created !")
		end


I don’t have any error but there is nothing in my DTextEntry in the other DFrame…
I don’t know if GetValue() is a good function to save the text of the player, but i don’t see an other function…

GetValue() should be fine. I still dont get why you need 2 frames and textentries for that. Just let the user tpye into one textentry and let him submit his report or whatever on click.

There is 2 windows :

  • One to create : you click on a nickname of player in the server and you write in a DTextEntry.
  • One to search : There is players who are clicked before and when you click on a player, there is the text of the player.

I don’t know how save all of that. There is one DTextEntry when you write you want to, and one which is no editable and when this is just the writing…
But i don’t know how save the name of the players and the text of EVERY player…
Very simple to understand, but not easy to create… Please help! Thanks in advance!