Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ WriteLog and duplicate lines

WriteLog and duplicate lines

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Rollanz   (26 posts)  Bio
Date Tue 15 Jul 2014 11:40 PM (UTC)
Message
I'm making a script to copy news posts in Achaea to a log file, and for some reason each line in my output log file is duplicated. Alias is like this:

<aliases>
  <alias
   match="^copyArchive (\d+)$"
   enabled="y"
   group="archive"
   regexp="y"
   send_to="12"
   keep_evaluating="y"
   sequence="100"
  >
  <send>numPosts=%1

archiveIndex=archiveIndex or 0
archiveIndex=archiveIndex+1

OpenLog("PublicArchives.txt",true)
EnableGroup("archiver",true)

world.Send("read ", archiveIndex)
</send>
  </alias>
</aliases>



And the trigger:


<triggers>
  <trigger
   group="archiver"
   keep_evaluating="y"
   match="^(.*)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>input_string="%1"

if string.find(input_string,"Type MORE if you wish to continue reading%.")~=nil then
world.Send("more")
elseif string.find(input_string,"PUBLIC SECTION (%d+)/(%d+)")==1 then
numPosts=numPosts-1
if numPosts==0 then
FlushLog()
CloseLog()
EnableGroup("archiver", false)
else
archiveIndex=archiveIndex+1
world.Send("read ", archiveIndex)
end
(%d+)/(%d+)"))
elseif string.match(input_string, "News &gt; ")==1 then
--print("ignore")
else
WriteLog(input_string)
Note("wrote log: ", input_string)
end
  </trigger>
</triggers>


And hints as to what is causing the duplication would be appreciated.
Top

Posted by Nick Gammon   Australia  (23,163 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 16 Jul 2014 03:33 AM (UTC)
Message
Once you have done an OpenLog all incoming lines are logged anyway, so doing a WriteLog would log them a second time.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rollanz   (26 posts)  Bio
Date Reply #2 on Wed 16 Jul 2014 05:16 AM (UTC)
Message
So the correct solution is as simple as gagging the trigger? Thanks!
Top

Posted by Nick Gammon   Australia  (23,163 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 16 Jul 2014 06:09 AM (UTC)
Message
Ah yes, if that was what that code was doing. :)

If I may suggest, indenting the inside of "if" blocks makes the structure easier to follow.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,242 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.