if = true and also executing else - 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: if = true and also executing else (/showthread.php?tid=95442) if = true and also executing else by dfnkt on 09-10-2010 at 08:47 PM
So I'm really new to jscript and looking for some input. I've got a script i'm working on that in the end will both lock the computer and set the status to away and the PSM to "I'm not here right now" or something of the sort. code: that fires up the window (for right now as part of the OnEvent_Initialize function) The dialog is a simple "Lock Computer?" with a 'yes' and 'no' button. Next I have a function setup to handle the clicking of 'yes' and 'no' that looks like this: code: Separately these two statements work just fine. However when you combine them using if/else you get some unwanted behavoir. Run the script and you can click "yes" and it locks the computer, if you click "No" the dialog closes but the computer also locks. How do you prevent it from running the if and else statements when you click No? Changing the else to an if on the btnyes section fixed this.. Is that really considered good to to say: If(blah) blah If(blah2) blah I've just always been accustomed to doing if/then/else/elseif type of a flow. RE: if = true and also executing else by CookieRevised on 09-10-2010 at 10:47 PM
For starters remove the ; at the end of Wnd.Close(7) if you want to use the short form. code: Thus what you actually wrote is (in Visual Basic terms): vb code:Or (in J(ava)Script Terms): js code: Hence your unexpected (but logical) behaviour. Hence also my suggestion to always use brackets { } and not trying to shorten stuff, especially when debugging. (this is a good example and exactly the reason why I did not agree with Eljay's comment here.) Also, J(ava)Script doesn't have an ELSEIF statement. If you want to do an ELSEIF you actually must do another IF inside the first ELSE. Thus either (in short form): js code:Or either (in longer form): js code:which is a shorter form of: js code: quote:For stuff like this, where there are only 2 things to compare the ControlId to, it depends on what you're used to. All forms are considered good, as long as you don't make any errors in the syntax of course Just remember that using multiple IF's is 'slower' than using the IF ELSE(IF) structure. This because in the first, all IF's will be executed and compared for a possible match, while in the later only the IF's and ELSE's up to a match will be executed. Either way, if there are many more things to compare ControlId to, then you could consider using a switch structure (equivalent of the Select Case statement in Visual Basic). RE: if = true and also executing else by dfnkt on 09-11-2010 at 04:04 AM
Thanks for all your info cookie. I'll double check my code and work on refactoring it. I was wondering if jscript supported something like case. RE: if = true and also executing else by Matti on 09-11-2010 at 09:19 AM
quote:Scripts can only add menu items to the Plus! Scripts menu using OnGetScriptMenu or with the <ScriptMenu> block in your ScriptInfo.xml. With more advanced coding, you might be able to add a menu item to the right-click menu of the task bar button or system tray icon, but that's about as far as you can go. Adding a button to the Messenger user interface itself is considered nearly impossible as it requires mad skills with memory hacks and UIB files - something which you can't do in a scripting environment. Even if they could technically allow Plus! scripts to add buttons to the Messenger UI, they wouldn't do it because it could easily be abused by malicious scripts and make Messenger look (even more) bloated. The scripts menu is there to centralize all scripts functionality in one place, making it easier for both users and developers to work with. You could however assign a system-wide hotkey to fire a script's function using the Windows API. I made a class for this sometime ago, you can find it in Countdown Live (GlobalHotkey.js) or Screenshot Sender 5 (Classes\_global_hotkey.js). Just copy that script file over to your script and use the class' methods wherever you need them. I see that there's little documentation about it, so if you're planning to use that class but you don't know how, just PM me and I'll help you out. RE: RE: if = true and also executing else by dfnkt on 09-11-2010 at 01:48 PM
quote: Well, I could see about assigning the script to be initialized when you hit Windows Key + L which is also a call to user32.dll and the LockWorkStation function. I am thinking now that a menu item on the Plus! menu makes the most sense. Currently I have the script utilizing the messengerStart event for testing, it prompts the user with a dialog and properly handles the yes or no button events. On yes the script closes the window created by the script, locks the computer, sets your presence to away and sets a personal status message of "I'm not here right now." I thought I remembered seeing something about taking user input? In the end if the user clicks "lock" or whatever it might be on the Plus! menu i'd a small dialog to come up and have them input a custom away message. On no it just closes the dialog. I've also got a small to-do for storing a pre-existing status message and restoring it and the user presence upon return (if possible). RE: if = true and also executing else by Eljay on 09-11-2010 at 02:04 PM
I made a small script called OnLock that detects when Windows is locked/unlocked and changes status. |