How to count a line of text?

Posted by Dacrian on Wed 07 Sep 2011 04:20 AM — 9 posts, 30,653 views.

Australia #0
Hi,

I know this is probably very simple, but I can't work it out. I want to count how many times a line of text appears, and after a certain number (eg. 4), execute a command.

here's the MUD output:


l papers in packet

Thin, flimsy, and prone to tearing, this is the sort of paper the Green Slab is printed on.  Ink spreads and blotches, pencils make holes in it, and it isn't even much good for fish and chips.  On the bright side, it's cheap.
It appears to have something written on it.
The sheet of cheap writing paper appears to be a magic scroll containing the spell Jogloran's Portal of Cheaper Travel.
Thin, flimsy, and prone to tearing, this is the sort of paper the Green Slab is printed on.  Ink spreads and blotches, pencils make holes in it, and it isn't even much good for fish and chips.  On the bright side, it's cheap.
It appears to have something written on it.
The sheet of cheap writing paper appears to be a magic scroll containing the spell Jogloran's Portal of Cheaper Travel.
etc ad nauseum


I want to count the line "The sheet of cheap writing paper appears to be a magic scroll containing the spell Jogloran's Portal of Cheaper Travel."

I stand in the shop, scribe the spell 4 times, put it into the packet. Currently I have the alias simply closing the packet at the end, then the trigger to sell the packet is the "You closed the packet" message. However I've had a few problems with packets being sold with less than 4 scrolls in them, so if I could only sell the packet when there's been four counts of that line, it would be much better for me.

here's what I tried in "send to script" with a trigger for that line.

@scrollcount = @scrollcount + 1


but it doesn't work. The error is:

[string "Trigger: "]:1: unexpected symbol near '@'

and then disconnects me from the MUD, something to do with compression.
any help for a slow-poke is appreciated, thanks in advance!
D
Australia Forum Administrator #1
Can you paste the actual trigger?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
Australia #2
<triggers>
  <trigger
   custom_colour="3"
   group="scribing"
   lines_to_match="2"
   keep_evaluating="y"
   match="The * containing the spell Jogloran's Portal of Cheaper Travel."
   send_to="12"
   sequence="100"
  >
  <send>@scrollcount = @scrollcount + 1</send>
  </trigger>
</triggers>


it's disabled so it doesn't crash me out every time it sees the line.

thanks :)
USA Global Moderator #3
Use SetVariable("scrollcount", GetVariable("scrollcount") + 1) instead of @scrollcount = @scrollcount + 1

[EDIT] Oops. Duh. Removed stupid suggestion.
Amended on Wed 07 Sep 2011 07:56 AM by Fiendish
Australia Forum Administrator #4
Only Fiendish's first suggestion will work.

@variable is read-only. You can't assign like that.

[EDIT]

This suggestion will work:


SetVariable("scrollcount", GetVariable("scrollcount") + 1) 

Amended on Wed 07 Sep 2011 08:20 AM by Nick Gammon
USA Global Moderator #5
Nick Gammon said:
Only Fiendish's first suggestion will work.
Second suggestion. I've amended my post.
Australia #6
thanks :)

more slow questions: How do I get it to perform checks on the variable? ie when the variable reaches a value, it performs an action, else it doesn't do it.
Here's what I thought would work:

<triggers>
  <trigger
   custom_colour="3"
   enabled="y"
   group="scribing"
   lines_to_match="2"
   keep_evaluating="y"
   match="The * containing the spell Jogloran's Portal of Cheaper Travel."
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("scrollcount", GetVariable("scrollcount") + 1)
if ("scrollcount" = "4",
Send ("sell packet")
end -- if)</send>
  </trigger>
</triggers>



but that kind of causes crashes as well. Probably because I have no idea what I'm doing! Please direct me to the nearest appropriate forum post, I'm sure this is an easy thing to do!

cheers
Amended on Thu 08 Sep 2011 02:54 AM by Dacrian
Australia Forum Administrator #7
You can learn a lot by reading the examples, like the plugins that come with the client. Anyway in your case:


if ("scrollcount" = "4",
Send ("sell packet")
end -- if)


needs to be more like:


if GetVariable ("scrollcount") == "4" then
  Send ("sell packet")
end -- if


For comparing greater or less than (or equals even) you are better off turning it into a number, like this:


if tonumber (GetVariable ("scrollcount")) == 4 then
  Send ("sell packet")
end -- if
Australia #8
great, thanks Nick. I'll keep reading and try not to stay in the slow class!