help with array
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

help with array

Started by suyang99, 08 January, 2004, 11:32:45

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

suyang99

when i input: !act thr 13 test
then found syntax error: bad argument #1 to 'gsub' (string expected, got nil)

bot = "adsdesign ?? DC++"
sigArr = {}
secArr = {}
thrArr = {}

function Main()
frmHub:GetMinShare()
frmHub:GetCurrentShareAmount()
frmHub:GetHubName()
frmHub:GetUsersCount()
MakeSig()
MakeSec()
MakeThr()
end

function DataArrival(user,data)
   if( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
      _,_,cmd = strfind(data,"%b<>%s+(%S+)")
      _,_,arg = strfind(data,"%b<>%s+%S+%s+(%S+)")
      _,_,arg2 = strfind(data,"%b<>%s+%S+%s+%S+%s+(%S+)")  
      _,_,arg3 = strfind(data,"%b<>%s+%S+%s+%S+%s+%S+%s(%S+)")
      --_,_,arg4 = strfind(data,"%b<>%s+%S+%s+%S+%s+%S+%s+%S+%s(.+)")
      profile = GetProfileName(user.iProfile)
      curuser = user.sName

      if (cmd=="!act") then
         if (profile=="Guest") then
            user:SendData(bot, "?????????รป???????????????!")
            return 1
         else
            if (arg=="sig") then
               if (arg2~=nil) then
                  user:SendData("*"..curuser.." "..sigArr[tonumber(arg2)])
               else
                  user:SendToNick(bot, "???????????, !act ")
               end
            elseif (arg=="sec") then
               if (arg2~=nil) then
                  if (arg3~=nil) then
                     nk = arg3
                  else
                     nk = "??????"
                  end
                  arrTmp = tokenize(secArr[tonumber(arg2)],"#")
                  user:SendData("*"..curuser.." "..arrTmp[1].." "..nk.." "..arrTmp[2])
               else
                  user:SendToNick(bot, "???????????, !act ")
               end
            elseif (arg=="thr") then
               if (arg2~=nil) then
                  if (arg3~=nil) then
                     nk = arg3
                  else
                     nk = "??????"
                  end
                  arrTmp = tokenize(thrArr[tonumber(arg2)],"#")
                  user:SendData("*"..curuser.." "..arrTmp[1].." "..nk.." "..arrTmp[2].." "..nk.." "..arrTmp[3])
               else
                  user:SendToNick(bot, "???????????, !act ")
               end
            elseif (arg=="help") then
               fFileHandle, sError = readfrom("acthelp.txt")
               local sLine = read()
               local sFileContent = ""
               if sLine then
                  sFileContent = sLine
                  while 1 do
                     sLine = read()
                     if not sLine then
                        break
                     else
                        sFileContent = sFileContent..sLine.."\r\n"
                     end
                  end
                  readfrom()   -- close filehandle
                  user:SendPM(bot,"\r\n\r\n"..sFileContent)
                  return 1
               else
                  user:SendPM(bot,"\r\n\r\n".."Nothing found in|")
               end
               readfrom()
               return 1
            end
            return 1
         end
         return 1
      end
   end
end

function tokenize (inString,token)
   _WORDS = {}
   local matcher = "([^"..token.."]+)"
   gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
   return _WORDS
end

function MakeSig()

   local handle = openfile("sig.dat", "r")
   if (handle~=nil) then
      local line = read(handle)
      while line do
         if (line ~= nil) then
            tinsert(sigArr, line)
         end
         line = read(handle)
      end
      closefile(handle)
   end

end

function MakeSec()

   local handle = openfile("sec.dat", "r")
   if (handle~=nil) then
      local line = read(handle)
      while line do
         if (line ~= nil) then
            tinsert(secArr, line)
         end
         line = read(handle)
      end
      closefile(handle)
   end

end

function MakeThr()

   local handle = openfile("thr.dat", "r")
   if (handle~=nil) then
      local line = read(handle)
      while line do
         if (line ~= nil) then
            tinsert(thrArr, line)
         end
         line = read(handle)
      end
      closefile(handle)
   end

end

plop

before you do:
arrTmp = tokenize(secArr[tonumber(arg2)],"#")
check if arg2 is actualy in the array and is a number.
this should solve it.
if secArr[tonumber(arg2)] then 
   arrTmp = tokenize(secArr[tonumber(arg2)],"#") 
else
   user:SendData(bot, arg2.." is a wrong arguments")
end
if arg2 is not in the array or a number gsub get a nil and that error shows up.
same stuff on the thrArr.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk