mushclient, com objects and hooks

Posted by Tspivey on Sun 30 Oct 2005 02:10 AM — 7 posts, 36,394 views.

Canada #0
Hello. I need to do the following:
1. create a com object, and keep it until mushclient exits.
2. on every line received (including world.note), send it to that com object.
this would exclude gags, etc.
is this possible?
I know how to create a com object with CreateObject, but not sure how to keep it there.
I"m also not sure how to hook into world.note.
USA #1
This is pretty simple. In both plugins and the main script file, any variable declaired 'outside' of a function is kept, so long as the script doesn't reload or the program exits.

For example, if this was your script:

dim a
dim d

sub Create_Objects (name, output, wilds)
  a = createobject("My_Object")
  b = createobject("My_Object")
  c = createobject("My_Object")
  dim d
  d = createobject("My_Object")
end sub

dim c

sub Do_Somestuff (...)
end sub


Both a and c will remain for as long as the script is not reloaded and/or you exit mushclient. b however will be lost as soon as Create_Objects returns control to mushclient, since its 'local' to Create_Objects, while the others are 'global'. 'd' is lost because you create a 'new' d, which is specifically declared 'local' by the 'dim' in that sub. (Or it should). Since b doesn't exist in the 'global' layer, its automatically assumed to be 'local' and thus vanishes, like d in this case, because it was created in the sub.

Note. All variables created using 'send to script' in triggers, aliases and timers exist in the 'global' space. This means they can overwrite values you intended to make permanent, unlike those created and destroyed in a sub, if you accidentally use the same name. This is why a, b, c, d are probably 'bad' names, while 'mywindow' or the like will prevent accidentally messing up. ;) Hope that helps.
Australia Forum Administrator #2
This is to do with the screen reader isn't it?

I have been thinking that there isn't really an easy way to capture every line that is typed in, displayed with world.note, and sent from the MUD.

Thus I have added an extra plugin callback into version 3.68 - OnPluginScreendraw.

This hooks into the "display line" routine, in such a way that it will capture input lines (things you type), note lines (from scripts) and also output lines that have not been gagged. This should work around your problem that your screen reader currently reads the lines that appear, even if they are about to be gagged.

A small plugin, like the one below, illustrates its use.

As for the COM side of it, as Shadowfyr suggests, you simply need to open the COM object (with CreateObject) early on, and store it in a variable outside any function.

You might create the COM object in OnPluginInstall.

The arguments to OnPluginScreendraw are:

type: type of line, where 0 = output line, 1 = note, 2 = command

log: are we planning to log it?

line: the text of the line itself


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, October 30, 2005, 3:29 PM -->
<!-- MuClient version 3.68 -->

<!-- Plugin "screendraw_test" generated by Plugin Wizard -->

<muclient>
<plugin
   name="screendraw_test"
   author="Nick Gammon"
   id="9afd5521a287f53094d238ea"
   language="Lua"
   purpose="testing OnPluginScreendraw"
   date_written="2005-10-30 15:27:42"
   requires="3.68"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginScreendraw (type, log, line)
  AppendToNotepad ("test", type, " ", log, " ", line, "\r\n")
end -- function
]]>
</script>


</muclient>

Canada #3
When will 3.68 be released, so I can try this feature and get some scripts going for it?
I think that this is the answer to some, if not most,
of my problems - calling the screen reader through its api is sometimes
better than letting a screen reader scrape the screen and not get the results it needs.
Thanks,
Tyler
Australia Forum Administrator #4
In the next couple of days.
Australia Forum Administrator #5
Version 3.68 is released now, see:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6055
Australia Forum Administrator #6
Also see this thread, which is about using the SAPI (speech API) to speak stuff easily:

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