General > Developers Corner

Lua Error string_gmatch. (Solved) (Thanks)

(1/1)

LuaTenshi:
So as you have seen in the title I am getting an error, and I don't know how to fix it.

May be its this part... strInput = string.Explode("_", strType[2])

but I don't know.


--- Code: ---function UpsClnStr( player,command,args )

strType = string.Explode("//", tostring(args))

if(args == "help") then ULib.tsay( player,"To clear a class type 'c//classType', To clear a certine model type 'm//modelString'" ) end

if(strType[1] == "m" or strType[1] == "M" or strType[1] == "m " or strType[1] == "M ") then

for _, ent in ipairs( ents.GetAll() ) do
if(ent:IsValid() and ent:GetModel() == strType[2]) then
if not (ent:IsWorld()) then
ent:Remove()
end
end
end

elseif(strType[1] == "c" or strType[1] == "C" or strType[1] == "c " or strType[1] == "C ") then

strInput = string.Explode("_", strType[2])

if( strInput[1] == "gmod" or strInput[1] == "prop" ) then

if not ( strInput[2] == "static" ) then

for _, ent in ipairs( ents.GetAll() ) do

if( ent:IsValid() and ent:GetClass() == strType[2] ) then

if not ( ent:IsWorld() ) then

ent:Remove()

end
end
end
end
end
end

ULib.tsay( nil,player:GetName().." has removed "..strType[2] )
end

concommand.Add( "ups_menu", UpsMenuContext )
concommand.Add( "ups_clnstr", UpsClnStr )

--- End code ---


--- Code: ---[@lua\includes\extensions\string.lua:34] bad argument #1 to 'string_gmatch' (string expected, got table)
--- End code ---

Megiddo:
Been a while since I've used low-level command callbacks, but I believe that the argument you have labeled "args" is a table, not a string as you're trying to treat it.

MrPresident:
That is correct. You would need to add the index to args to make it work.

Navigation

[0] Message Index

Go to full version