Does MUSHclient use DDE?
Posted by Deqitosv on Sat 28 Jul 2001 08:50 PM — 18 posts, 73,075 views.
MUSHclient exposes an extensive list of interfaces via the COM method, which are documented at: MUSHclient functions
After a considerable amount of mucking about I got something like that to work. :)
Here is what I did:
- Start Visual Basic
- Create a new ActiveX EXE project
- Under Properties change the class "(Name)" field from "Class1" to "MC_class"
- Under Properties change the project "(Name)" field from "Project1" to "MC_callback"
- Go to the Project menu and click on References
- When the References window opens click on the Browse button and navigate to the "MUSHclient.tlb" file that came as part of the MUSHclient download, then click Open.
- Confirm that "MUSHclient" appears in the list of "Available References" and is ticked.
- Open the Object Browser (F2) or use the View Menu -> Object Browser, and change the top combo-box to "MUSHclient". You will see "World" appear in the list of classes down the bottom of that window. Double-click on World and you will see all the supported world functions (eg. AddAlias, AddTimer and so on). Close the browser.
- In the code window for the project type in a test subroutine:
Sub TestNote(theworld As World)
theworld.Note "This is a test"
End Sub
- Go to the File menu and click on Save Project. Accept the suggested file names (MC_callback.vbp and MC_class.cls).
- Go to the File menu and click on "Make MC_callback.exe".
The above steps have created a ActiveX file that can be called from MUSHclient.
Testing the ActiveX project
- Start MUSHclient and open a world
- Make sure scripting is active - VBscript language
- Type:
/dim testobject
/set testobject = createobject ("mc_callback.mc_class")
/testobject.TestNote (world)
/set testobject = nothing
- You should see "this is a test" echo on the output window. What the lines above are doing is:
- Making a variable "testobject"
- Assigning to it a reference to the new class "mc_callback.mc_class" from your Visual Basic application
- Calling the "TestNote" subroutine in that class. We pass to it the reference to our current world. The "TestNote" subroutine uses that reference to call "world.note"
- By setting the testobject to "nothing" we release the reference to that world
This is just an example program. However once you have it working you can expand it somewhat. For instance, you could store the "world" reference in a global variable and use it later on for other subroutine calls without having to pass it down every time.
theworld.send "say hi there"
In the code window (in VB) replace my earlier example with the following. You will note that I am saving the "world" variable into a "public" variable, that will persist between calls. then you can do (in MUSHclient):
/testobject.Anothertest
This will say "Hi there" to the previously-saved world.
New lines are in bold.
Public savedworld As World
Sub TestNote(theworld As World)
theworld.Note "This is a test"
Set savedworld = theworld ' save variable
End Sub
Sub AnotherTest()
If Not savedworld Is Nothing And Not IsEmpty(savedworld) Then
savedworld.Send "say Hi there!"
End If
End Sub
Lets say i make a program in Vbasic, and want to communicate with mushclient.
DO i have to communicate with an "active x exe" prementioned, then into MUSH, or can I Integrate these together? If it's possible could you please post some snippets of code just showing the jist of it :)
Thankye everyone
Can you give a brief example?
In Nick's post:
/dim testobject
/set testobject = createobject ("mc_callback.mc_class")
/testobject.TestNote (world)
/set testobject = nothing
What exactly is passed on to mc_callback as 'world'? Is it possible to hardcode that value in the VB project without having to originate it in Mushclient? I am trying to make a millisecond timer which involves using a script component (.wsc file) but I can't seem to work out how to use callbacks in mushclient.tlb. I actually haven't managed to even reference the .tlb in the script component yet, but I am hoping to do that sooner or later, though it appears that registering that .tlb is somewhat problematic - unless the main problem is myself :)
The "world" reference is the actual address of the relevant MUSHclient world in memory. Since COM is an Object management system (hence the O) it deals in object (executable code). You can't "remember" it, the address will be different every time.
As for the .tlb file, I doubt you can use it in a script, it is for if you are writing a program in full Visual Basic. In that case it isn't necessary, just helpful. Here is an example. If you start up VB and open a new project, and then go to the Project menu > References, you can click the Browse button, and use that to add the mushclient.tlb file. After you do that you should see something like this:

Once you have done that then you can use the object browser in your project, and it will show you the names of all the MUSHclient script functions, and also hopefully auto-complete the names and arguments if you happen to use a MUSHclient world in your program ...

Here's what I actually did:
1. Mushclient script .Run's a standalone script (.wsf)
2. .wsf creates an instance of a .wsc component
3. .wsc component uses callbacks to talk to Mushclient (to grab the timer's parameters and send a command to it when the timer fires).
The reason for using a separate script is to gain access to the Wscript object and avoid hanging Mushclient when I use Wscript.Sleep.
1. Create a wsf instance and pass it the 'world' handle.
2. Have the wsf create an instance of the .wsc.
3. Pass the world handle again to the new object so it knows what world it needs to talk to.
Looks like you hae either missed the last one or are doing it wrong and Mushclient is 'fixing' the problem by spawning a brand new world each time you execute a command. However, unless you specific gave it a value, the handle you are passing is likely EMPTY and I doubt Mushclient is setting it for you.
One 'possible' fix, assuming I am right, would be to do:
dim whandle as WORLD
whandle = whandle.getworld
however, this would only work for 'new' worlds, not existing ones. Actually I am not sure it would work at all, so... lol But I am sure that your .wsc has no clue 'which' world it is supposed to talk to and that is causing the problem.
If you try to CreateObject ("mushclient.world") or something similar, then MUSHclient tries to create a new world (as asked). The safer thing, which it sounds like you are doing is to get MUSHclient to create your script object, not your script object to create MUSHclient.