Shoutbox

help me debugging this script - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: help me debugging this script (/showthread.php?tid=71199)

help me debugging this script by Wakaki on 01-30-2007 at 11:49 AM

code:
//Global Variables:
var DefWelcomeMsg = "";
var DefGoodbyeMsg = "";

//Functions
function OnEvent_Initialize(MessengerStart) {
    var fsObj = new ActiveXObject("Scripting.FileSystemObject");
   
    var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', 1)
    DefWelcomeMsg = fileObj.ReadAll();
    fileObj.Close();
   
    //Not sure, but I think you could probably reuse the fileObj too.
    var fileObj2 = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', 1)
    DefGoodbyeMsg = fileObj2.ReadAll();
    fileObj2.Close();
}

function OnGetScriptMenu(Location) {
    var ScriptMenu ="<ScriptMenu>";
    ScriptMenu +="<MenuEntry Id=\"window\">Polite Preferences</MenuEntry>";
    ScriptMenu +="</ScriptMenu>";
    return ScriptMenu;
}

function OnEvent_MenuClicked(MenuId, Location, Wnd) {
    switch(MenuId) {
        case "window":
            var PlusWnd = MsgPlus.CreateWnd( 'windows_new.xml', 'Polite', 0 );
            PlusWnd.SetControlText("EdtWelcomeMsg", DefWelcomeMsg)
            PlusWnd.SetControlText("EdtGoodbyeMsg", DefGoodbyeMsg)
            break;
    }
}

function OverwriteFile (file, content) {
    var fileObj = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, 2);
    fileObj.write(content);
    fileObj.Close();
}

function OnPoliteEvent_CtrlClicked(PlusWnd, CtrlId) {
    if(CtrlId == "Btnlol") {
        OverwriteFile("defwelcomemsg.txt", PlusWnd.GetControlText("EdtWelcomeMSg"));
        OverwriteFile("defgoodbyemsg.txt", PlusWnd.GetControlText("EdtGoodbyeMsg"));
    }
}

function OnEvent_Signin(Email) {
    var Message = DefWelcomemsg;
    MsgPlus.DisplayToast("Hello", Message);
}

function OnEvent_Signout(Email) {
    var Message = DefGoodbyemsg;
    MsgPlus.DisplayToast("Goodbye", Message);
}

this is my script can you see the ctrlclic on button=btnlol??

that overwrite function doesn;t work plz help me!

debug ouput:
code:
Function called: OnEvent_Signin
Error: 'DefWelcomemsg' is not defined.
       Line: 58. Code: -2146823279.
Function OnEvent_Signin returned an error. Code: -2147352567

plz help
RE: help me debugging this script by markee on 01-30-2007 at 12:18 PM

You need to spell variables with the same case for everything.  'Msg' is not the same as 'msg' in JScript, that is where your problem is, well your current one anyway, I know how it is when I write scripts....


RE: help me debugging this script by Wakaki on 01-30-2007 at 12:26 PM

thnak you thed isplay toasts work now but my overwrite function stil doesn't and there isn't any debug output.

als when i saved everything the textfiles were emptyied


o wait the files aren't empty but the variab;es are:S


edit: that is now solved but there is more
this is wat i get when i cahnge the input in the window and click save

nothing happens and the debug screen syas:
code:
Function called: OnGetScriptMenu
Function called: OnEvent_MenuClicked
Function called: OnPoliteEvent_CtrlClicked


RE: help me debugging this script by roflmao456 on 01-30-2007 at 10:15 PM

is the control ID "Btnlol" ?


RE: help me debugging this script by Wakaki on 01-31-2007 at 02:03 PM

yes thats the control id


RE: help me debugging this script by Wakaki on 02-01-2007 at 11:55 AM

somebody plz tell me i'm just starting with scripts so.


RE: RE: help me debugging this script by tryxter on 02-01-2007 at 01:28 PM

quote:
Originally posted by Wakaki
this is wat i get when i cahnge the input in the window and click save

nothing happens and the debug screen syas:
code:
Function called: OnGetScriptMenu
Function called: OnEvent_MenuClicked
Function called: OnPoliteEvent_CtrlClicked



What's supposed to happen?

Well, the problem seems to be the ControlId. Check if that control has the same name on the interface and on the if condition.

code:
function OnPoliteEvent_CtrlClicked(PlusWnd, CtrlId) {
    if(CtrlId == "Btnlol") {
        OverwriteFile("defwelcomemsg.txt", PlusWnd.GetControlText("EdtWelcomeMSg"));
        OverwriteFile("defgoodbyemsg.txt", PlusWnd.GetControlText("EdtGoodbyeMsg"));
    }
}

RE: help me debugging this script by Wakaki on 02-01-2007 at 02:53 PM

it is and the reason i thaught it didn't worked is because i need to restart messenger

now can you help me with that problem??
cause i wnat that i you chance the goodbye message that when you log out you see the new one ??

i now have this:

code:
//global variables:   
var DefWelcomeMsg = "";
var DefGoodbyeMsg = "";

//functions
function OnEvent_Initialize(MessengerStart) {
var fsObj = new ActiveXObject("Scripting.FileSystemObject");

var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', 1)
DefWelcomeMsg = fileObj.ReadAll();
fileObj.Close();

var fileObj2 = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', 1)
DefGoodbyeMsg = fileObj2.ReadAll();
fileObj2.Close();

}


to give the variables a value but this now only happens when messenger starts an di want it always updated like every 5 second or every second

____________________________________________________
p.s.

another little question how do you "say" window.close ??

RE: help me debugging this script by Wakaki on 02-01-2007 at 03:10 PM

does anybody know?]


RE: help me debugging this script by tryxter on 02-01-2007 at 06:02 PM

quote:
Originally posted by Wakaki

cause i wnat that i you chance the goodbye message that when you log out you see the new one ??

i now have this:
code:
//global variables:   
var DefWelcomeMsg = "";
var DefGoodbyeMsg = "";

//functions
function OnEvent_Initialize(MessengerStart) {
var fsObj = new ActiveXObject("Scripting.FileSystemObject");

var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', 1)
DefWelcomeMsg = fileObj.ReadAll();
fileObj.Close();

var fileObj2 = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', 1)
DefGoodbyeMsg = fileObj2.ReadAll();
fileObj2.Close();

}



to give the variables a value but this now only happens when messenger starts an di want it always updated like every 5 second or every second

____________________________________________________
p.s.

another little question how do you "say" window.close ??

Sorry, but I can't understand your "english". Can you try to explain it a little better?

About the window close function, you can use:
code:
Wnd.Close(1);
Wnd is the variable containing the window object.
RE: help me debugging this script by Matti on 02-01-2007 at 06:24 PM

It would be a terrible idea to do that every 5 seconds. You could better listen for a file modification every 30 seconds and if it changed, change your variables.

Take a look at the code snippet here, and you can make something like:

code:
var ListenInterval = 30000; //30 seconds

//This has been token from the code snippet, all credits go to OcuS
var FileModificationDates = [];
function ListenForFileModification(FilePath, Callback) {
   var DateLastModified = GetFileModificationDate(FilePath);
   if (DateLastModified === false) return false;

   Callback = Callback || function(FilePath) {};
   FileModificationDates[FilePath] = {
      file : FilePath,
      date : DateLastModified,
      callback : Callback
   }
   MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
   return true;
}

function GetFileModificationDate(FilePath) {
   var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
   if (!FileSystem.FileExists(FilePath)) return false;
   var File = FileSystem.GetFile(FilePath);
   return '' + File.DateLastModified + '';
}

function OnEvent_Timer(TimerId) {
   var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
   if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
      var FilePath = TimerMatchLSTN[1];
      var DateLastModified = GetFileModificationDate(FilePath);
      if (DateLastModified === false) return false;

      if (DateLastModified != FileModificationDates[FilePath].date){
         FileModificationDates[FilePath].callback(FilePath);
         FileModificationDates[FilePath] = undefined;
         return true;
      }
      MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
      return true;
   }
}

function OnEvent_Initialize(MessengerStart) {
//Here comes your original stuff...
//And here are our listening function calls!
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', SetDef);
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', SetDef);

}

function SetDef(FilePath) {
   //I'll use a regular expression for this one, it checks if the file's right and captures the welcome or

goodbye
   if(FilePath.test(/\\def(welcome|goodbye)msg\.txt$/i) {
      //We'll open our file
      var File = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(FilePath, 1);
      //Here we'll see what it has captured and save it in the right variable
      switch(RegExp.$1) {
         case "welcome":
            DefWelcomeMsg = File.ReadAll();
            break;
         case "goodbye":
            DefGoodbyeMsg = File.ReadAll();
            break;
      }
      //At the end, we'll close the file
      File.Close();
      //That's all folks!
   }
}



I'm too nice for these guys... :sad:
RE: RE: help me debugging this script by Wakaki on 02-01-2007 at 09:23 PM

quote:
Originally posted by Mattike
It would be a terrible idea to do that every 5 seconds. You could better listen for a file modification every 30 seconds and if it changed, change your variables.

Take a look at the code snippet here, and you can make something like:
code:
var ListenInterval = 30000; //30 seconds

//This has been token from the code snippet, all credits go to OcuS
var FileModificationDates = [];
function ListenForFileModification(FilePath, Callback) {
   var DateLastModified = GetFileModificationDate(FilePath);
   if (DateLastModified === false) return false;

   Callback = Callback || function(FilePath) {};
   FileModificationDates[FilePath] = {
      file : FilePath,
      date : DateLastModified,
      callback : Callback
   }
   MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
   return true;
}

function GetFileModificationDate(FilePath) {
   var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
   if (!FileSystem.FileExists(FilePath)) return false;
   var File = FileSystem.GetFile(FilePath);
   return '' + File.DateLastModified + '';
}

function OnEvent_Timer(TimerId) {
   var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
   if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
      var FilePath = TimerMatchLSTN[1];
      var DateLastModified = GetFileModificationDate(FilePath);
      if (DateLastModified === false) return false;

      if (DateLastModified != FileModificationDates[FilePath].date){
         FileModificationDates[FilePath].callback(FilePath);
         FileModificationDates[FilePath] = undefined;
         return true;
      }
      MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
      return true;
   }
}

function OnEvent_Initialize(MessengerStart) {
//Here comes your original stuff...
//And here are our listening function calls!
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', SetDef);
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', SetDef);

}

function SetDef(FilePath) {
   //I'll use a regular expression for this one, it checks if the file's right and captures the welcome or

goodbye
   if(FilePath.test(/\\def(welcome|goodbye)msg\.txt$/i) {
      //We'll open our file
      var File = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(FilePath, 1);
      //Here we'll see what it has captured and save it in the right variable
      switch(RegExp.$1) {
         case "welcome":
            DefWelcomeMsg = File.ReadAll();
            break;
         case "goodbye":
            DefGoodbyeMsg = File.ReadAll();
            break;
      }
      //At the end, we'll close the file
      File.Close();
      //That's all folks!
   }
}



I'm too nice for these guys... :sad:


thank you thank you thank you

i will test it in the morning tommorow

p.s. youre right youre too nice:D:wicked: