Help! Can't get Lua to read player's chat

**So, I want to make this code where it puts the ‘@’ symbol before the player’s text, but I don’t know how to make it so Lua reads the text.

For example: If the player types “Hi!” in the DTextEntry of the Derma panel I’m working on, I want it to put “@Hi!” into the chat.

I can’t figure out how to make it so it inputs the player’s text, only the text that I set. Please help!**


local EnterText = vgui.Create ("DTextEntry", DermaPanel)
EnterText:SetPos(50,50)
EnterText:SetTall(20)
EnterText:SetWide(160)
EnterText:SetEnterAllowed(true)
EnterText.OnEnter = function ()
	 RunConsoleCommand("say",hi..ply:GetName()..": WHERE THE CUSTOM TEXT SHOULD BE.")
	DermaPanel:SetVisible(false)
	end
local hi= "@"

I want to make it so that where it says “WHERE THE CUSTOM TEXT SHOULD BE.” it says what the player typed in the DTextEntry of my DermaPanel

P.S. I know this is most likely a dumb question considering I started learning Lua less than a week ago, I appreciate you taking the time to read and help me. :-]

You don’t have to type in bold. Anyways, where is “hi” defined since you’re not using it as a string.

Oh, my bad! Forgot to copy that part into my post, but it’s there in my code. Thanks for mentioning that, just added it to the post.

You should localize your variable, and you don’t need the parentheses at all to define a variable. You can just do


local hi = "@"

Done. :smiley: Thanks for letting me know, but I still don’t know how to make it so it gets what the player typed. D:

You have hi being defined after you call it. So at the time its actually being called its nil. Put it above the other stuff

You could try using DTextEntry.GetValue()

Thank you, I fixed that.

[editline]26th April 2014[/editline]

Thank you! It worked!