[I maid the change, in my CASE section]??? - 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: [I maid the change, in my CASE section]??? (/showthread.php?tid=72746)
[I maid the change, in my CASE section]??? by xsylvain2 on 03-17-2007 at 02:05 PM
Ok, I tranlate in english my entire script, for Melin talk in englis whit more choce. I add all channel TrueVoice.
My problem is : the status never change when I click on my menu. Do you have a idea?
In registry write ok, but read I don't know.
My bug is In case section, unly defaut section work and case 1 at 10 dont work.
code: function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd) {
switch(MenuItemId) {
case "MerlinState":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"EnabledStatus", (Enabled = !Enabled), "REG_DWORD");
OnEvent_Initialize(false);
break;
case "Woman_CH1":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 1);
Change_voice();
break;
case "Woman_CH2":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 2);
Change_voice();
break;
case "Man_CH1":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 3);
Change_voice();
break;
case "Man_CH2":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 4);
Change_voice();
break;
case "Man_CH3":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 5);
Change_voice();
break;
case "Man_CH4":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 6);
Change_voice();
break;
case "Man_CH5":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 7);
Change_voice();
break;
case "Man_CH6":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 8);
Change_voice();
break;
case "Man_CH7":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 9);
Change_voice();
break;
case "Man_CH8":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 10);
Change_voice();
break;
//default:
//new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 3);
//Change_voice();
//break;
//case "Refresh":
//Change_voice()
//break;
}
}
function OnGetScriptMenu(Location){
ScriptMenu = "<ScriptMenu>";
ScriptMenu += " <MenuEntry Id=\"Status\" Enabled=\"False\">"+State+"</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"SVoice\" Enabled=\"False\">"+VOICE+"</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"MerlinState\">" + (Enabled ? "[ OFF ]" : "[ ON ]") + "</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <SubMenu Label=\"woman\">";
ScriptMenu += " <MenuEntry Id=\"Woman_CH1\" > Woman channel #1 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Woman_CH2\" > Woman channel #2 </MenuEntry>";
ScriptMenu += " </SubMenu>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <SubMenu Label=\"Man\">";
ScriptMenu += " <MenuEntry Id=\"Man_CH1\" > Man channel #1 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH2\" > Man channel #2 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH3\" > Man channel #3 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH4\" > Man channel #4 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH5\" > Man channel #5 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH6\" > Man channel #6 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH7\" > Man channel #7 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH8\" > Man channel #8 </MenuEntry>";
ScriptMenu += " </SubMenu>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"Refresh\" > Refresh all </MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"Author\" Enabled=\"False\">Maid by XSylvain2</MenuEntry>";
ScriptMenu += "</ScriptMenu>";
return ScriptMenu;
}
function Change_voice(){
if(Merlin){
try{
CHANNEL = new ActiveXObject("WScript.Shell").RegRead(MsgPlus.ScriptRegPath+"CHANNEL");
} catch (err){
CHANNEL = false;
}
switch(CHANNEL) {
case 1:
Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273008}");
VOICE = "Woman channel #1";
break;
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:
Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273000}");
VOICE = "Man channel #1";
}
Debug.Trace("CHANNEL = "+CHANNEL);
Debug.Trace("VOICE = "+VOICE);
}
}
RE: A litle bug, I'm confused by Matti on 03-17-2007 at 02:27 PM
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);
}
RE: A litle bug, I'm confused by xsylvain2 on 03-17-2007 at 03:08 PM
I have make this change, but it is necessary that I click 2 times to make a change of channel. The debuger write change, but the status does not change.
code: function OnGetScriptMenu(Location){
ScriptMenu = "<ScriptMenu>";
ScriptMenu += " <MenuEntry Id=\"Status\" Enabled=\"False\">"+State+"</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"SVoice\" Enabled=\"False\">"+VOICE+"</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"MerlinState\">" + (Enabled ? "[ OFF ]" : "[ ON ]") + "</MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <SubMenu Label=\"woman\">";
ScriptMenu += " <MenuEntry Id=\"Woman_CH1\" > Woman channel #1 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Woman_CH2\" > Woman channel #2 </MenuEntry>";
ScriptMenu += " </SubMenu>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <SubMenu Label=\"Man\">";
ScriptMenu += " <MenuEntry Id=\"Man_CH1\" > Man channel #1 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH2\" > Man channel #2 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH3\" > Man channel #3 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH4\" > Man channel #4 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH5\" > Man channel #5 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH6\" > Man channel #6 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH7\" > Man channel #7 </MenuEntry>";
ScriptMenu += " <MenuEntry Id=\"Man_CH8\" > Man channel #8 </MenuEntry>";
ScriptMenu += " </SubMenu>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"Refresh\" > Refresh all </MenuEntry>";
ScriptMenu += " <Separator/>";
ScriptMenu += " <MenuEntry Id=\"Author\" Enabled=\"False\">Maid by XSylvain2</MenuEntry>";
ScriptMenu += "</ScriptMenu>";
return ScriptMenu;
}
function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd) {
switch(MenuItemId) {
case "MerlinState":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"EnabledStatus", (Enabled = !Enabled), "REG_DWORD");
OnEvent_Initialize(false);
break;
case "Woman_CH1":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 1);
Change_voice();
break;
case "Woman_CH2":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 2);
Change_voice();
break;
case "Man_CH1":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 3);
Change_voice();
break;
case "Man_CH2":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 4);
Change_voice();
break;
case "Man_CH3":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 5);
Change_voice();
break;
case "Man_CH4":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 6);
Change_voice();
break;
case "Man_CH5":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 7);
Change_voice();
break;
case "Man_CH6":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 8);
Change_voice();
break;
case "Man_CH7":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 9);
Change_voice();
break;
case "Man_CH8":
new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 10);
Change_voice();
break;
//default:
//new ActiveXObject("WScript.Shell").RegWrite(MsgPlus.ScriptRegPath+"CHANNEL", 3);
//Change_voice();
//break;
//case "Refresh":
//Change_voice()
//break;
}
}
function Change_voice(){
if(Merlin){
try{
CHANNEL = new ActiveXObject("WScript.Shell").RegRead(MsgPlus.ScriptRegPath+"CHANNEL");
} catch (err){CHANNEL = false};
switch(CHANNEL) {
case 1:
Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273008}");
VOICE = "Woman channel #1";
break;
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:
Merlin.TTSModeID = ("{CA141FD0-AC7F-11D1-97A3-006008273000}");
VOICE = "Man channel #1";
}
Debug.Trace("CHANNEL = "+CHANNEL);
Debug.Trace("VOICE = "+VOICE);
return VOICE;
}
|