Getting " autorun/client/PlayerTest.lua:20: function arguments expected near ','"

Here is the code:

local tplayers = {}
local tcount = 0

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 250,250 )
DermaPanel:SetSize( 500, 50 )
DermaPanel:SetTitle( “Enter name of player to target and press enter:” )
DermaPanel:ShowCloseButton( true )
DermaPanel:SetVisible( false )
DermaPanel:MakePopup()

local DermaText = vgui.Create( “DTextEntry”, DermaPanel )
DermaText:SetPos( 20,25 )
DermaText:SetTall( 20 )
DermaText:SetWide( 450 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
DermaPanel:SetVisible( false )
local players = ents.FindByClass(“player”)
for k, v in pairs(players) do
if string.match((v:Nick), (DermaText:GetValue())) then
local tcount = tcount + 1
local tplayers[tcount] = v
end
end
if !(tplayers[1] = “”) then
ply:ChatPrint(“There wasnt found any players with “…DermaText:GetValue()…” in theres names.”)
local okey = 0
elseif !(tplayers[2] = “”) then
ply:ChatPrint(“There was multiple players with “…DermaText:GetValue()…” in theres name.”)
local okey = 0
else
local okey = 1
end
player = tplayers[1]
ply.ChatPrint(player:Nick)
end

local function pfToggle( player, command, arguments )
if DermaPanel:IsVisible = true then
DermaPanel.SetVisible( false )
else
DermaPanel:SetVisible( true )
end
concommand.Add(“pf_toggle”, pfToggle)

Any ideas whats wrong?

if string.match((v:Nick), (DermaText:GetValue())) then

it should be v:Nick() not v:Nick

Also, on your for loop, you can just do "for k, v in pairs( player.GetAll() ) do instead of that ents.GetAll stuff you have going on there.

[lua]-- lua tags are your friend
local tplayers = {}
local tcount = 0

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 250,250 )
DermaPanel:SetSize( 500, 50 )
DermaPanel:SetTitle( “Enter name of player to target and press enter:” )
DermaPanel:ShowCloseButton( true )
DermaPanel:SetVisible( false )
DermaPanel:MakePopup()

local DermaText = vgui.Create( “DTextEntry”, DermaPanel )
DermaText:SetPos( 20,25 )
DermaText:SetTall( 20 )
DermaText:SetWide( 450 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
DermaPanel:SetVisible( false )
local players = ents.FindByClass(“player”)
for k, v in pairs(players) do
if string.match((v:Nick), (DermaText:GetValue())) then
local tcount = tcount + 1
local tplayers[tcount] = v
end
end
if !(tplayers[1] = “”) then
ply:ChatPrint(“There wasnt found any players with “…DermaText:GetValue()…” in theres names.”)
local okey = 0
elseif !(tplayers[2] = “”) then
ply:ChatPrint(“There was multiple players with “…DermaText:GetValue()…” in theres name.”)
local okey = 0
else
local okey = 1
end
player = tplayers[1]
ply.ChatPrint(player:Nick)
end

local function pfToggle( player, command, arguments )
if DermaPanel:IsVisible = true then
DermaPanel.SetVisible( false )
else
DermaPanel:SetVisible( true )
end
concommand.Add(“pf_toggle”, pfToggle)[/lua]
The only problem I can see is that you haven’t got a matching end for the pfToggle function.
Here’s a neater way of writing it:
[lua]concommand.Add(“pf_toggle”, function(player, command, arguments)
if DermaPanel:IsVisible = true then
DermaPanel.SetVisible( false )
else
DermaPanel:SetVisible( true )
end
end)[/lua]
Rather than having a local function which you’re only going to use passed to the concommand.Add function, why not use it as an anonymous function.

Sorry if im idiot but this is my first real script…
Im testing it

[editline]11:22AM[/editline]

Okey, i tested it but it says:
"
LuaGetfile: Not Loading autorun/client/TargetPlayerTest.lua~
Couldn’t include file ‘autorun/client/TargetPlayerTest.lua~’ (File not found)
"
Any ideas?

I don’t think that ~ should be in there.

-snip-

[editline]01:12PM[/editline]

I fixed the errors but it says:

Warning: vgui.Create failed to create the VGUI component (DFrame)

What??

You’re using = instead of ==. = is the assignment operator (technically not true in lua but it acts nearly the same) while == is the comparison operator.
[lua]
if !(tplayers[1] == “”) then
ply:ChatPrint(“There wasnt found any players with “…DermaText:GetValue()…” in theres names.”)
local okey = 0
elseif !(tplayers[2] == “”) then
ply:ChatPrint(“There was multiple players with “…DermaText:GetValue()…” in theres name.”)
local okey = 0
else
local okey = 1
end
[/lua]
You also have problems with these:
[lua]
– ply.ChatPrint(player:Nick)
ply:ChatPrint(player:Nick)
end

local function pfToggle( player, command, arguments )
–if DermaPanel:IsVisible = true then
if DermaPanel:IsVisible() then – this is equivalent and works
– DermaPanel.SetVisible( false )
DermaPanel:SetVisible( false ) – a:b() is the method invocation
else
DermaPanel:SetVisible( true )
– of course this whole block could be replaced with DermaPanel:SetVisible( not DermaPanel:IsVisible() )
end[/lua]

Thx, but i just edited :open_mouth:

[editline]02:14PM[/editline]

Anyone?

-bump-

[editline]05:24PM[/editline]

Pleeeeeeease???

[editline]05:33PM[/editline]

It says:
Warning: vgui.Create failed to create the VGUI component (DFrame)
Any ideas whats wrong?

The only thing I can think of is that it’s trying to run that code Serverside, the only way I know of getting that error is if the component isn’t defined, but DFrame is a valid component name.


Attempt to index nil "vgui"

No, the problem is he is running the code as soon as possible, so the vgui library might not have included the DFrame file yet. Basically, create the menu in an InitPostEntity hook.

[lua]-- lua tags are your friend
local tplayers = {}
local tcount = 0

hook.Add(“InitPostEntity” , “MyDermaDelay” , function()
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 250,250 )
DermaPanel:SetSize( 500, 50 )
DermaPanel:SetTitle( “Enter name of player to target and press enter:” )
DermaPanel:ShowCloseButton( true )
DermaPanel:SetVisible( false )
DermaPanel:MakePopup()

local DermaText = vgui.Create( "DTextEntry", DermaPanel )
DermaText:SetPos( 20,25 )
DermaText:SetTall( 20 )
DermaText:SetWide( 450 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
	DermaPanel:SetVisible( false )
	local players = ents.FindByClass("player")
	for k, v in pairs(players) do
		if string.match((v:Nick), (DermaText:GetValue())) then
			local tcount = tcount + 1
			local tplayers[tcount] = v
		end
	end
	if !(tplayers[1] = "") then
		ply:ChatPrint("There wasnt found any players with "..DermaText:GetValue().." in theres names.")
		local okey = 0
	elseif !(tplayers[2] = "") then
		ply:ChatPrint("There was multiple players with "..DermaText:GetValue().." in theres name.")
		local okey = 0
	else
		local okey = 1
	end
	player = tplayers[1]
	ply.ChatPrint(player:Nick)
end

local function pfToggle( player, command, arguments )
if DermaPanel:IsVisible = true then
	DermaPanel.SetVisible( false )
else
	DermaPanel:SetVisible( true )
end
concommand.Add("pf_toggle", pfToggle)

end )[/lua]

Okey, thx!
Im trying now

[editline]11:22PM[/editline]

A lil bit more in depth description of this: http://wiki.garrysmod.com/?title=String.match ?

It’s all about finding out if a given string matches a pattern, some examples are:
checking whether it’s a string of numbers
checking if it’s a filename by being a bock, then a dot, then another block

The important bit is that you can use it to get parts of other strings as well, like getting the file extension from a filepath, getting someone’s first name or if you want to get complicated you could use a variant to parse a text file.

So is it the right fuction for finding if a string present in another string?

I use string.find

For detecting if a substring exists in a string they’re pretty much equivalent in function, though perhaps not in Complexity. I tend to use it with arbitrary patterns though, so it’s handy to find out what exactly it matched.