Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
MidNor
Newbie


Joined: 04 Aug 2011
Posts: 6

PostPosted: Sat Nov 26, 2011 6:40 am   

Attatching to Cmud from another application
 
I can not believe how easy it was to to code the OLE Automation, I will be using it regularly from now on.
May I ask a few questions?
    Is there a page with descriptions for the Properties and Methods? Besides the Zmud list.
    Or better even any form of documentation or demos.

    How do I get the output from the MUD into my application?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4715
Location: Pensacola, FL, USA

PostPosted: Sat Nov 26, 2011 8:07 am   
 
You might be able to manage it with some COM scripting, but I only know of it, not how to do it.
_________________
Discord: Shalimarwildcat
Reply with quote
MidNor
Newbie


Joined: 04 Aug 2011
Posts: 6

PostPosted: Sat Nov 26, 2011 7:06 pm   
 
I understand from http://www.zuggsoft.com/devkit/sampleplugin.txt that procedure MUDInput(H: Integer; var P: WideString); safecall; is called whenever new data arrives.
I have seen procedures being trapped before but can not remember how it is done.
Any form of assistance or direction would be greatly appreciated.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Dec 01, 2011 3:20 am   
 
I deduced most of what I needed by reading this. There are pointers to other topics on this page, also.
Once you grasp that CMUD is both a client and a server and, therefore, that the COM interface is bidirectional, the rest is easy.

Here is a code snippet from a C# application requesting data from CMUD:
Code:

...
private string getpath(string to)
        {
            int funcMapvnum = 370;

            int.TryParse(Desk.sess.cMUDFunction(funcMapvnum), out fromroom);

            toroom = getroom(to);

            if (fromroom != toroom) return buildpath(fromroom, toroom);

            return null;
        }
...

Desk.sess is a reference to the CMUD COM library.
_________________
Sic itur ad astra.
Reply with quote
MidNor
Newbie


Joined: 04 Aug 2011
Posts: 6

PostPosted: Thu Dec 01, 2011 3:09 pm   
 
The cMUDFunction function is most useful but I can not seem to call any custom functions that I create and 370 does not exist.
I have CmudPro and my custom functions start at 67 which for the life of me only returns nothing.
I am currently looking at dumping all the incoming text in a variable and then reading the variable with:

var
vars : Variant;
ss := cc.CurrentSession;
...
...
vars := ss.GetVar('stun', 'Triggers');
memo1.Lines.Add(VarToStr(vars.OLEVal));

I can read the default values but not the OLEVal.

Something does not feel right in this concept.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4715
Location: Pensacola, FL, USA

PostPosted: Thu Dec 01, 2011 8:04 pm   
 
due to limitations certain CMUD settings (aliases and i assume variable/functions as well) cannot start with a numeric character.

Try naming it f370 instead of 370
_________________
Discord: Shalimarwildcat
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Fri Dec 02, 2011 2:18 am   
 
The list of ComID values to use with the cMUDFunction can be found here.

If you want to try the above code client-side, put the following snippet in an alias and execute it:
Code:

$funcMapvnum = 370

$fromroom = %session.cMUDFunction($funcMapvnum)

#PRINT $fromroom


Now you have to examples: Using CMUD as server (the C# snippet) and the other using CMUD as client (the alias)

Note that %seesion is equivalent to %cmud.CurrentSession. (%cmud and %session are predefined variables)

Also, as you might have seen, I use int.TryParse to process the return from the function. This is because the value returned is flagged as a WideString, that is, a unicode string. However, if you run it on the client side this does not matter as CMUD will assign the return value to an Auto variable.

So that there is no confusion, the reason Desk.sess is a reference to the CMUD COM library is that Desk contains a reference to the application's control section and sess is a field within that section that references IcMUDSession.

In the documentation which I pointed to in my original post, replace IzMUD with IcMUD. Both libraries are identical except for the field names.
_________________
Sic itur ad astra.
Reply with quote
MidNor
Newbie


Joined: 04 Aug 2011
Posts: 6

PostPosted: Mon Dec 05, 2011 2:15 pm   
 
Wow this was a challenge but here are the solution that worked for me.
Thank you all for your assistance in finding the solution. I hope that this will help someone else not to spend days to get this working.
In Cmud I have a triger that adds everyline to a stringlist variable.
Then I pull the variable and reset it back to empty by calling an alias.
Here are the Delphi code
ss is a currentsession
InputBuff is a global string
<---- Snip ---->
function TForm1.GetMudInput:String;
var
sInput : string;
buff: Char;
iSkip, iCount: Integer;
begin
sInput := InputBuff + ss.EvaluateStr('@MudInput'); // Get the variable
if Length(sInput) > 0 then
InputBuff := '|'+sInput; // When pullung fresh info add a |
ss.ProcessCommand('ClearInput'); // Call alias that cleans the variable
iSkip := 0;

for iCount := 1 to Length(InputBuff) do
begin
if iSkip > 0 then
dec(iSkip) // Handle escaped "|"
else if ((InputBuff[iCount] = '"') and (InputBuff[iCount+1] = '|') and (InputBuff[iCount+2] = '"')) then
begin
sInput := sInput + '|'; // Escaped "|";
iSkip := 2;
end
else if (InputBuff[iCount] = '|') then
break // End of line
else
sInput := sInput + InputBuff[iCount];
end;
InputBuff := copy(InputBuff, iCount+1);
GetMudInput := sInput;
end;

< ---- Snip ---->
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net