[not really a release/help] my first 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: [not really a release/help] my first script (/showthread.php?tid=63402)
[not really a release/help] my first script by andrey on 07-17-2006 at 12:50 AM
Yeah, this has been my first attempt evar at J(ava)script and programming in general..
And the result of five() days learning Jscript from scratch is: "auto-send ISI"
The (pretty simple) idea was, that when I type a command in the conversation window, the script gets the Internal Sound Identifier for a Custom Sound (e.g. #CC506B2EDBC4) from the clipboard (if it's present) and sends the sound to the contact.
(might be useful when you're extremely lazy, browsing mpsounds.net and you want to send just one sound from a huge soundpack (the ISI is called Sound ID over there, btw))
Maybe that's not such a big thing, (not very useful either), but it's an achievement for me, and I'm pretty happy that I got it working
I'll post the code below, and ask you to comment on it (style, efficiency and so on)
Commands:
enable script: +isi
disable script: -isi
send sound: isi
code: var enabled = false;
var ISI;
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
if(Message == "+isi") {
enabled = true;
return("");
}
if(Message == "-isi") {
enabled = false;
return("");
}
if(Message == "isi") {
if(enabled == true)
return(startISI());
}
}
function startISI() {
readClipboard();
if(matchISI() == true) {
return(Message = "/sound " + ISI);
} else {
return("");
}
}
//http://shoutbox.menthix.net/showthread.php?tid=63067
function readClipboard() {
var CF_TEXT = 1;
var CF_OEMTEXT = 7;
var CF_UNICODETEXT = 13;
ISI = false;
try {
if(Interop.Call("User32", "OpenClipboard", 0)) {
if(Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT)) {
var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_UNICODETEXT);
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var size = Interop.Call("Kernel32", "GlobalSize", hClipboardData);
var str = Interop.Allocate(size+2);
Interop.Call("Kernel32", "RtlMoveMemory", str, pchData, size);
ISI = str.ReadString(0);
var unlocked = Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
} else {
Interop.Call("User32", "CloseClipboard");
return(false);
}
Interop.Call("User32", "CloseClipboard");
}
} catch(exeption) {
Interop.Call("User32", "CloseClipboard");
return(false);
}
return(ISI);
}
function matchISI() {
var re = /^\#[A-F0-9]{12}$/;
var foundArray = re.test(ISI);
if(foundArray == true) {
return(true);
} else {
return(false);
}
}
RE: [not really a release/help] my first script by Chestah on 07-17-2006 at 01:03 AM
Looks good , just a few suggestions.
return(""); - all your returns can be in this format: return "";. There is no need for the brackets.
Also it doesn't matter for your script but in programming in general its good to abstract components of your code so you can reuse them. For instance your readclipboard() function reads the data and puts it into the variable ISI. It would be better if instead it just returned the string contents of the clipboard and then in your code you would do something like this:
code: ISI = readClipboard();
You could do something similiar to the matchISI() function and pass in the ISI variable. It doesn't really have any impact on this script but its just a programming practise that you can use to reuse code .
Good work!
RE: [not really a release/help] my first script by RaceProUK on 07-17-2006 at 08:54 AM
quote: Originally posted by Chestah
Also it doesn't matter for your script but in programming in general its good to abstract components of your code so you can reuse them. For instance your readclipboard() function reads the data and puts it into the variable ISI. It would be better if instead it just returned the string contents of the clipboard and then in your code you would do something like this:
code: ISI = readClipboard();
You could do something similiar to the matchISI() function and pass in the ISI variable. It doesn't really have any impact on this script but its just a programming practise that you can use to reuse code .
Good work!
It matters in scripts too: it's programming after all. Personally, I'd recommend this as a matter of style: having global variables can be quite dangerous.
|