[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  WriteLog and duplicate lines

WriteLog and duplicate lines

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


Posted by Rollanz   (26 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] 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
[Go to top] top

Posted by Rollanz   (26 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] 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
[Go to top] 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.


11,139 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]