What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Read Text from a file

Pages: (3): « First « 1 [ 2 ] 3 » Last »
Read Text from a file
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Read Text from a file
The highlighted line was forgotten.
jscript code:
function ReadLineFromFile(sFile, nLine)
{
    var f = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(sFile, 1 /* ForReading */);
    var s = f.ReadAll();
    f.Close()
    var FileContents = s.split('\r\n');
    return FileConents[nLine - 1];
}

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage)
{
    var m;
    if (m = /^\/([^ \n\r\v\xA0\/][^ \n\r\v\xA0]*)[\s\xA0]?([\s\S]*)/.exec(sMessage))
    {
        var command = m[1].toLowerCase();
        var parameter = m[2];
        if (command == 'acserv')
        {
            var line = ReadLineFromFile("C:\\Program Files\\AssaultCube_v1.1.0.3\\config\\saved.cfg", 255);
            // line now contains the 255th line from saved.cfg
            line = line.replace('alias "serverinfo [', '');
            line = line.replace(']', '');
>>>            return line;<<<
        }
    }
    return sMessage;
}
11-07-2010 06:30 PM
Profile E-Mail PM Find Quote Report
TehGoatLord
New Member
*


Posts: 12
Joined: Nov 2010
O.P. RE: Read Text from a file
Nope. It's still not working
11-07-2010 06:48 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Read Text from a file
You guys are still using the bugged version of ReadLineFromFile(). On the last line, "FileContents" is misspelled, which I already mentioned in my previous post.

Another possible issue could be that the file you're trying to read is saved as Unicode. By default, OpenTextFile reads the file as ASCII so you need to pass in an extra parameter to override this behavior. Therefore, I added an extra parameter to the function which takes care of this. You could try to detect whether a file is saved as ASCII or Unicode, but that requires some Win32 trickery.
js code:
function ReadLineFromFile(sFile, nLine, bUnicode) {
    var f = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(sFile, 1 /* ForReading */, false, (bUnicode ? -1 : 0));
    var s = f.ReadAll();
    f.Close();
    var FileContents = s.split(/\r?\n/);
    if(nLine > FileContents.length) return false; // implement some error handling here?
    return FileContents[nLine-1];
}

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    var m;
    if (m = /^\/([^ \n\r\v\xA0\/][^ \n\r\v\xA0]*)[\s\xA0]?([\s\S]*)/.exec(sMessage)) {
        var command = m[1].toLowerCase();
        var parameter = m[2];
        if (command == 'acserv') {
            var line = ReadLineFromFile("C:\\Program Files\\AssaultCube_v1.1.0.3\\config\\saved.cfg", 255, false); // change false to true if Unicode
            // line now contains the 255th line from saved.cfg
            line = line.replace('alias "serverinfo [', '');
            line = line.replace(']', '');
            return line;
        }
    }
    return sMessage;
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-07-2010 07:42 PM
Profile E-Mail PM Web Find Quote Report
TehGoatLord
New Member
*


Posts: 12
Joined: Nov 2010
O.P. RE: Read Text from a file
Not workin, man ._. I don't the MSGPlus can call the function at all.

/acserv

doesn't work.
11-07-2010 08:01 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Read Text from a file
What version of Windows Live Messenger do you have?
11-07-2010 08:07 PM
Profile E-Mail PM Find Quote Report
TehGoatLord
New Member
*


Posts: 12
Joined: Nov 2010
O.P. RE: Read Text from a file
14.0.8117.416
11-07-2010 08:14 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Read Text from a file
Could you be a bit more specific about what exactly isn't working? When I run the last snippet I posted, it works flawlessly and I'm on the same version of Messenger as well (WLM 2009).
  • Are you sure you saved your script files as Unicode (UCS-2 Little Endian)?
  • Does the script debugger window report any errors?
  • Have you tried debugging it by adding some Debug.Trace() lines to see what the value of the variables are at certain points?
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-07-2010 08:22 PM
Profile E-Mail PM Web Find Quote Report
TehGoatLord
New Member
*


Posts: 12
Joined: Nov 2010
O.P. RE: Read Text from a file
[Image: acservmsnfault.JPG]

There it is

I'm a pretty much noob at this debugging and stuff ._. what exactly do I need to do starting from the beginning?
11-07-2010 08:30 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Read Text from a file
Where are you pasting the snippets into? Are you using the built-in script editor of Plus! Live? If so, does it say "Script has successfully started" in the debugger when you click "Save All"?

What exactly is at line 255 of that saved.cfg file of yours? I see you were doing something with /connect for your mIRC script, perhaps it fails because the line read from the file starts with a slash?

With debugging, I mean trying to get an idea about what state the script is in at certain points during execution. For example, it might be interesting to place a Debug.Trace call just after the command parser, to check whether the command is correctly detected:
js code:
// ...
if (command == 'acserv') {
    Debug.Trace('Found command /acserv');
    var line = ReadLineFromFile( //...
Another interesting value to check is what is sent to the chat window. Just before the return statement, you could throw in a Debug.Trace call and see what the value of line is.
js code:
line = line.replace(']', '');
Debug.Trace('line = '+line);
return line;
These are just some examples of how one could find out what's happening inside the script. Ultimately, you should be able to pinpoint the location where something doesn't go as planned and to fix the problem. And that is how we program stuff, through trial and error. :)

This post was edited on 11-07-2010 at 08:49 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-07-2010 08:42 PM
Profile E-Mail PM Web Find Quote Report
TehGoatLord
New Member
*


Posts: 12
Joined: Nov 2010
O.P. RE: Read Text from a file
This is what the script says:

code:
Function called: OnEvent_ChatWndSendMessage
Function called: OnEvent_ChatWndSendMessage
Error: Object doesn't support this property or method (code: -2146827850)
       File: AssaultCube Read.js. Line: 18.
Function OnEvent_ChatWndSendMessage returned an error. Code: -2147352567

and this is the cfg file

http://www.rantages.com/saved.cfg


Also, the connect is added later on in my mIRC alias.
11-07-2010 08:51 PM
Profile E-Mail PM Find Quote Report
Pages: (3): « First « 1 [ 2 ] 3 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On