PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: thelizno on 17 November, 2005, 08:09:46

Title: !news wont trigger without args
Post by: thelizno on 17 November, 2005, 08:09:46
Yes, I am new to lua.. and this is all a working progress..
but I cannot seem to find anything wrong with this code!!

Quotefunction ToArrival(user, data)

   s,e,to,fr,pf,cmd,args = string.find(data, "^$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S)(%S+)%s+(.*)")
   
   if to == botnick and pf == "!" then
      if cmd == "news" and args ~= nil then SendPmToNick(fr,botnick,"** Announcing news ..") end
      if cmd == "addnews" then SendPmToNick(fr,botnick,"** Adding news .."..args) end
   end

end

PMing the bot..
'!news' Results: None.
'!addnews' Results: None.
'!news applepie' Results: ' ** Announcing news ..'

WHAT is wrong here?? I even included if args ~= nil .. but that didn't work either.
Please help me out. :)
Title:
Post by: Dessamator on 17 November, 2005, 08:29:51
if args ~= nil
This means that, that command  will only  function when there is an arg.
Hope it helps.
Title:
Post by: thelizno on 17 November, 2005, 08:32:24
QuoteOriginally posted by Dessamator
if args ~= nil
This means that, that command  will only  function when there is a trig.
Hope it helps.
Oh, I see.. :P
if arfs ~= nil was removed..
It still gets the same result thou. >:(
Title:
Post by: thelizno on 17 November, 2005, 08:33:17
[17/11-05 08:30:34] !news
[17/11-05 08:30:38] !addnews ss
[17/11-05 08:30:38] <@mayhem> ** Adding news ..ss
[17/11-05 08:30:41] !news ss
[17/11-05 08:30:41] <@mayhem> ** Announcing news ..
Title:
Post by: Dessamator on 17 November, 2005, 08:51:24
s,e,to,fr,pf,cmd,args = string.find(data, "^$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S)(%S+)%s+(.*)")

Well that was only 1 error in the scripting, the second one is the string.find, this part particularly :
%s+(.*)"

Quote+ 1 or more repetitions (returns nil if not found)
* 0 or more repetitions (returns "" on 0 repetitions)

In other words the string.find will only work when there is a space after the trig.It has nothing to do with what u write after it, even if u write "!news ", notice the space, it will work .

Hope it Helps, btw these are just hints since ur trying to learn.
Title:
Post by: thelizno on 17 November, 2005, 08:58:18
Thank you! :D

s,e,to,fr,pf,cmd,args = string.find(data, "^$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S)(%S+)(.+)").. ran perfectly!