Counting logs

Posted by Cedron on Thu 07 Aug 2014 04:36 PM — 3 posts, 17,614 views.

#0
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.
USA #1
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.
Australia Forum Administrator #2
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 = {}