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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Counting logs
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Counting logs

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


Posted by Cedron   (5 posts)  [Biography] bio
Date Thu 07 Aug 2014 04:36 PM (UTC)
Message
I am in a room full of logs, some marked by their owners, some not. How would I go about counting and keeping a running total for each woodworker? In my limited mind, I'm guessing I'll need to make a trigger for each different persons name and another catch all for those lumber logs not named.

Here is an excerpt with one person and what the generic would be.
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(186).
A dusky ironwood log is stacked on a pallet, ready for shipping (187).
A dusky ironwood log is stacked on a pallet, ready for shipping (188).
A dusky ironwood log is stacked on a pallet, ready for shipping (189).
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(190).
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(191).
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(192).
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(193).
A dusky ironwood log is stacked on a pallet, ready for shipping, marked
with the image of a forest of tiny trees surrounded by a circle ("Ceras")
(194).

The number in the parenthesis is a running total of each log in the room. Given this many logs, its not something you want to tally yourself.

Thanks guys.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #1 on Thu 07 Aug 2014 07:28 PM (UTC)
Message
The most obvious solution to me would be a regex trigger to highlight the stacks that don't have an owner. Provided of course all of the claimed ones don't have "shipping (#)" at the end of the line. Another option would be to have the regex kick the unclaimed ones to a text window rather than highlighting inline.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Thu 07 Aug 2014 08:39 PM (UTC)

Amended on Thu 07 Aug 2014 08:40 PM (UTC) by Nick Gammon

Message
This should do it. Use 3 triggers, one for each line. The second two are initially disabled.


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^A dusky ironwood log is stacked on a pallet, ready for shipping(, marked| \((?'count'\d+)\)\.)$"
   name="log_trigger_1"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

count = tonumber ('%&lt;count&gt;')

-- make sure global variables exist
unowned = unowned or 0
owners = owners or {}

if count then
  unowned = unowned + count
  print ("Total unowned =", unowned)
else
  EnableTrigger ("log_trigger_2", true)
end -- if

</send>
  </trigger>


  <trigger
   custom_colour="2"
   match="^with the image of a forest of tiny trees surrounded by a circle \(&quot;(?'owner'[^&quot;]+)&quot;\)$"
   name="log_trigger_2"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

-- remember owner
current_owner = '%&lt;owner&gt;'

EnableTrigger ("log_trigger_2", false)
EnableTrigger ("log_trigger_3", true)

</send>
  </trigger>

  <trigger
   custom_colour="2"
   match="^\((?'count'\d+)\)\.$"
   name="log_trigger_3"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

owners [current_owner] = owners [current_owner] or 0

owners [current_owner] = owners [current_owner] + tonumber ('%&lt;count&gt;')

EnableTrigger ("log_trigger_3", false)

require "tprint"
tprint (owners)

</send>
  </trigger>

</triggers>



Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


This assumes your output wraps the way you showed. If not, you may have to fiddle around a bit.

The first trigger counts the unowned logs (since that line has a count on it). If not, it enables the second trigger.

The second trigger captures the owner's name and remembers it. It then disables itself and enables the third trigger.

The third trigger captures the count of the owned logs, and then disables itself.

The first and third triggers report the running totals. You may want to change how that is done, and have some mechanism for resetting the totals.

eg. To reset them all (like, when you first enter this room):


unowned = 0
owners = {}

- 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.


2,635 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 FutureQuest]