What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [I maid the change, in my CASE section]???

[I maid the change, in my CASE section]???
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: A litle bug, I'm confused
code:
try{ CHANNEL = Boolean (new ActiveXObject("WScript.Shell").RegRead(MsgPlus.ScriptRegPath+"CHANNEL" ));} catch (err){CHANNEL = true}
That's the big problem here. What this would do, is read the key and converted it to a Boolean (true or false). In normal cases, the key contains a not-null value, and therefore CHANNEL gets a true value. Then, you check if CHANNEL is equal to 1 (and it is, since true == 1) and thus the voice is set to the first one. Therefore, you should not convert CHANNEL at all!

Also, it's recommend that if you have a lot of if-statements which check the same value (in this case the value of CHANNEL), you use a switch..case statement. It looks cleaner and in most of the cases it makes your code better readable. ;)

code:
function Change_voice(){
  if(Merlin){
    try {
      CHANNEL = new ActiveXObject("WScript.Shell").RegRead(MsgPlus.ScriptRegPath+"CHANNEL");
    } catch (err) {
      CHANNEL = false;
    }

  //switch..case-statements look much cleaner than multiple if-statements ;-)
  switch(CHANNEL) {
    case 1:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273008}");
      VOICE = "Woman channel #1";
      break; //This is necessary, otherwise it'll execute the following statements too!
    case 2:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273009}");
      VOICE = "Woman channel #2";
      break;
    case 3:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273000}");
      VOICE = "Man channel #1";
      break;
    case 4:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273001}");
      VOICE = "Man channel #2";
      break;
    case 5:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273002}");
      VOICE = "Man channel #3";
      break;
    case 6:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273003}");
      VOICE = "Man channel #4";
      break;
    case 7:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273004}");
      VOICE = "Man channel #5";
      break;
    case 8:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273005}");
      VOICE = "Man channel #6";
      break;
    case 9:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273006}");
      VOICE = "Man channel #7";
      break;
    case 10:
      Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273007}");
      VOICE = "Man channel #8";
      break;
    default:
      //When CHANNEL is not a number from 1 to 10, for example when the key doesn't exist
      //and CHANNEL is set to false (0), you can tell the script what to do here.
      //A default statement doesn't need a break statement at the end.
      Debug.Trace("VOICE could not be set: value of CHANNEL is invalid.");
  }
  Debug.Trace("CHANNEL = "+CHANNEL);
  Debug.Trace("VOICE = "+VOICE);
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-17-2007 02:27 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[I maid the change, in my CASE section]??? - by xsylvain2 on 03-17-2007 at 02:05 PM
RE: A litle bug, I'm confused - by Matti on 03-17-2007 at 02:27 PM
RE: A litle bug, I'm confused - by xsylvain2 on 03-17-2007 at 03:08 PM


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