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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  How to count a line of text?

How to count a line of text?

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


Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Wed 07 Sep 2011 04:20 AM (UTC)
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 07 Sep 2011 05:41 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Reply #2 on Wed 07 Sep 2011 05:47 AM (UTC)
Message
<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 :)
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Wed 07 Sep 2011 07:16 AM (UTC)

Amended on Wed 07 Sep 2011 07:56 AM (UTC) by Fiendish

Message
Use SetVariable("scrollcount", GetVariable("scrollcount") + 1) instead of @scrollcount = @scrollcount + 1

[EDIT] Oops. Duh. Removed stupid suggestion.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 07 Sep 2011 07:30 AM (UTC)

Amended on Wed 07 Sep 2011 08:20 AM (UTC) by Nick Gammon

Message
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) 


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Wed 07 Sep 2011 07:58 AM (UTC)
Message
Nick Gammon said:
Only Fiendish's first suggestion will work.
Second suggestion. I've amended my post.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Reply #6 on Thu 08 Sep 2011 02:46 AM (UTC)

Amended on Thu 08 Sep 2011 02:54 AM (UTC) by Dacrian

Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 08 Sep 2011 03:15 AM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Reply #8 on Thu 08 Sep 2011 03:41 AM (UTC)
Message
great, thanks Nick. I'll keep reading and try not to stay in the slow class!
[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.


18,505 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]