ULX

Author Topic: Lua Error string_gmatch. (Solved) (Thanks)  (Read 3556 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Lua Error string_gmatch. (Solved) (Thanks)
« on: September 15, 2011, 04:11:05 PM »
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: [Select]
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 )

Code: [Select]
[@lua\includes\extensions\string.lua:34] bad argument #1 to 'string_gmatch' (string expected, got table)
« Last Edit: September 25, 2011, 05:05:10 PM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Lua Error string_gmatch.
« Reply #1 on: September 15, 2011, 08:41:32 PM »
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.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Lua Error string_gmatch.
« Reply #2 on: September 15, 2011, 09:34:01 PM »
That is correct. You would need to add the index to args to make it work.