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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Counting asterisks - *

Counting asterisks - *

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


Pages: 1 2  

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Wed 14 Feb 2007 07:11 PM (UTC)
Message
In my favorite MUD, enemy difficulty is displayed as such:

Armor: *****
Damage:**** :
Health:******* :

Is there any way (and I won't be surprised if there isn't, but it couldn't hurt to ask) to count how many of those * there are? My hope is to turn the above output into something like this:

Armor: ***** 5
Damage:**** : 4
Health:******* : 7
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Wed 14 Feb 2007 09:12 PM (UTC)
Message
I don't think it's possible with regular expressions directly, however, I think you could capture on the string, omit it from output, and then send it to a script; the script would count the asterisks, and then output to world the original line plus the count of asterisks.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #2 on Thu 15 Feb 2007 02:33 PM (UTC)
Message
Sounds reasonable, but I have no idea how to do it.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 16 Feb 2007 04:12 AM (UTC)
Message
In Lua you can count symbols easily enough using string.gsub. This small test program illustrates this:


test = "Health:******* :"

_, count = string.gsub(test, "%*", "*")

print (test .. " " .. count) --> Health:******* : 7

- Nick Gammon

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

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #4 on Fri 16 Feb 2007 03:14 PM (UTC)

Amended on Fri 16 Feb 2007 07:19 PM (UTC) by ErockMahan

Message
I did some research, so here's how I'm doing it in VBScript:

Itcounted = "%1"
world.send Len(Itcounted)

Unfortunately, it seems that this will count spaces as well, and that's not something I want. But more digging around and testing and such yielded the following solution:


function charcount(strRequest, char)
tmp = Split(Trim(strRequest), char)
charcount = UBOUND(tmp)
end function

strRequest = "%1"
world.note "Total:" & Cstr (charcount(strRequest, "*")) & ""


The problem I have now is that it puts each of these "world.note"s on a new line instead of at the end of the one already there. Is there any way to replace the line or simply add the output at the end of the line its giving me?
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 17 Feb 2007 05:57 AM (UTC)
Message
If you omit the line from output, and then redisplay it (with world.Tell) it will appear without starting a new line. Then append, with world.Note the extra stuff you want.

- Nick Gammon

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

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #6 on Tue 20 Feb 2007 04:06 PM (UTC)
Message
Simple enough though that sounds, I'm afraid that I don't understand. See, whenever I "Omit from output," I can't get it to display anything, whether I world.note or world.tell.
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #7 on Tue 20 Feb 2007 05:34 PM (UTC)

Amended on Tue 20 Feb 2007 05:35 PM (UTC) by Shaun Biggs

Message
I've had that problem before, but only until the mud sent back more text. Sometimes MC can set the world.note part farther down than the screen shows, but that might just be an issue with Wine.

Try putting a few messages in there to make sure the script engine is getting to your code. You can delete these test lines later, but they might point out when you're running into trouble.

sub rating( trig_name, trig_line, wildcards )
  'test line
  world.note "script called"
  '
  count = string.gsub(trig_line, "%*", "*")
  world.note trig_line .. ": " .. count
end sub


If that doesn't help you out, just cut/paste your whole script into a post and we can take a look at it from there.

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 20 Feb 2007 07:07 PM (UTC)
Message
There has been a design issue with Omit from Output, and scripts that do a Note, for a while now.

Basically MUSHclient omits everything from the start of the matching line, to the end of the output buffer, including anything you note.

However in the latest version you can now do "send to script - after omit", which changes the order of things around a bit, and the Note (or Tell) will appear in the output window.

- Nick Gammon

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

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #9 on Tue 20 Feb 2007 08:02 PM (UTC)

Amended on Tue 20 Feb 2007 08:03 PM (UTC) by ErockMahan

Message
My code is as follows (enabled, keeps evaluating, sending to script):

It triggers on:

Armor: * (I know that it is working too, as my temporary solution is to turn it black so that it isn't visible and my world.note stands out)

It sends:

Itcounted = "%1"
world.note "Armor:" & Cstr (Len(Itcounted)) & ""


[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Tue 20 Feb 2007 09:09 PM (UTC)
Message
See this post:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4776

Please use that technique to copy and paste here your actual trigger.

- Nick Gammon

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

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #11 on Tue 20 Feb 2007 10:59 PM (UTC)
Message
<triggers>
<trigger
custom_colour="13"
enabled="y"
keep_evaluating="y"
match="Health:* :"
send_to="12"
sequence="100"
>
<send>function charcount(strRequest, char)
tmp = Split(Trim(strRequest), char)
charcount = UBOUND(tmp)
end function

strRequest = "%1"
world.note "Health:" &amp; Cstr (charcount(strRequest, "*")) &amp; ""</send>
</trigger>
</triggers>



Wow...I never knew
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #12 on Wed 21 Feb 2007 12:11 AM (UTC)

Amended on Wed 21 Feb 2007 12:14 AM (UTC) by Shaun Biggs

Message
Try this in the send field:

sub barcount( trig_name, trig_line, wildcards )
  tmp = Split( Trim( wildcards[ 1 ] ), &amp; )
  world.note trig_line .. Cstr( UBound( tmp ) )
end sub

That should work... I think. I'm not very familiar with VBscript, since I haven't actually used it in a good 4-5 years. It should in theory display the lines just like you had them in your first post, and you can put this in your script section and have multiple triggers call it. Or you could use regex and have the trigger line be
(Health|Armor|Damage):(\**)

And then just change the wildcards accordingly

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Wed 21 Feb 2007 04:41 AM (UTC)
Message
I suggested making it "send to script - after omit". You had:

send_to="12"

This is "send to script". It should be 14 (script after omit). Just amend the drop-down box in the trigger. Then you should be able to omit from output, and still do your notes.

- Nick Gammon

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

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #14 on Wed 21 Feb 2007 03:42 PM (UTC)
Message
I'm using Mushclient version 3.78 for Windows (as per the downloads section) and I do not see an "after omit" option.

An attempt to paste the code with the "send_to=14" replacing the "send_to=12" yields this error message:

Line 7: Value '14' too large in numeric attribute named 'send_to'. Range is 0 to 13. (trigger not loaded)
[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.


40,984 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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]