Counting asterisks - *

Posted by ErockMahan on Wed 14 Feb 2007 07:11 PM — 16 posts, 66,978 views.

#0
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
USA #1
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.
#2
Sounds reasonable, but I have no idea how to do it.
Australia Forum Administrator #3
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
#4
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?
Amended on Fri 16 Feb 2007 07:19 PM by ErockMahan
Australia Forum Administrator #5
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.
#6
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.
USA #7
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.
Amended on Tue 20 Feb 2007 05:35 PM by Shaun Biggs
Australia Forum Administrator #8
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.
#9
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)) & ""


Amended on Tue 20 Feb 2007 08:03 PM by ErockMahan
Australia Forum Administrator #10
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.
#11
<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
USA #12
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
Amended on Wed 21 Feb 2007 12:14 AM by Shaun Biggs
Australia Forum Administrator #13
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.
#14
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)
Australia Forum Administrator #15
Recent versions are announced on the forum, and not recommended on the downloads page until a trial period, in case they have bugs. See:

http://www.gammon.com.au/forum/?id=7537