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);
}