Help - I'm new to scripting! |
Author: |
Message: |
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. Help - I'm new to scripting!
I've just started working on an "Instant Response" script, that can send a message or a /command after someone says something to you. But I have a few problems since I am very new to this:
1) I don't know how to make an enable/disable option (for chat windows and the contact list) in the script option menu.
2) I don't know how to make an options screen, to change the delay and message, either!
If anyone can give me the basic code for it, I would really appreciate it.
I have attached the script file in the message below, and as an attachment (in script format - ".js").
jscript code: var SettingMessage;
var SettingTimer;
function OnEvent_Initialize(MessengerStart)
{
SettingMessage = "/nudge";
SettingTimer = 100;
}
function OnEvent_Timer(TimerID)
{
Debug.Trace("Timer launched");
Messenger.OpenChat(TimerID).SendMessage(SettingMessage);
}
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
if (Origin != Messenger.MyName) {
Debug.Trace("Message received");
var Contacts = ChatWnd.Contacts;
var e = new Enumerator(Contacts);
for(; !e.atEnd(); e.moveNext()) {
var Contact = e.item();
Debug.Trace(" " + Contact.Email);
}
if (Message != SettingMessage)
{
var Contacts = ChatWnd.Contacts;
var e = new Enumerator(Contacts);
var NoContacts = 0;
for(; !e.atEnd(); e.moveNext()) {
var Contact = e.item();
Debug.Trace(" " + Contact.Email);
NoContacts = NoContacts + 1;
}
Debug.Trace(NoContacts);
if (NoContacts == 1) {
MsgPlus.AddTimer(Contact.Email, SettingTimer);
Debug.Trace("Timer started");
}
}
}
}
|
|
11-15-2008 03:12 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Help - I'm new to scripting!
For the menu option look at something like this
Volv's reply to Tips
As far as creating a Window this is all done in XML. Take a look at some other script and see how they do things and don't forget to check out the official documentation on the site.
|
|
11-25-2008 04:31 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: Help - I'm new to scripting!
Okay, I get the menu, but how can I use the menu to enable and disable the script?
|
|
11-26-2008 08:16 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Help - I'm new to scripting!
Uusing this: jscript code: function OnEvent_MenuClicked(sMenuId){
if(sMenuId=="mnuItem1"){
...
}
}
You can set a boolean variable that will enable or disable the script.
This post was edited on 11-26-2008 at 08:40 PM by matty.
|
|
11-26-2008 08:23 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: Help - I'm new to scripting!
I get that, but I'm still not sure how to make a boolean variable to enable/disable the script... (sorry, I'm really new to this).
|
|
11-26-2008 09:01 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Help - I'm new to scripting!
Do you want the ability to prevent nudging if the script is "disabled" is that the affect you are trying to achieve?
Also I know you are new but you can cut down on some code for example:
jscript code: // Create an object to store our sent messages
var mySentMessages = {};
var bEnabled = true;
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
if (mySendMessages[ChatWnd.Handle] != Message) {
Debug.Trace("Message received");
if (Message != '/nudge') {
if (ChatWnd.Contacts.Count == 1 && bEnabled == true) {
for (var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()) {
// store the new chat window in a variable
var pChat = Messenger.OpenChat(e.item().Email)
// check if the chat window's typing area is enabled and the user isn't blocked
if (pChat.EditChangeAllowed == true && e.item().Blocked == false) {
pChat.SendMessage('/nudge');
}
}
}
}
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
mySentMessages[ChatWnd.Handle] = Message; // store the last sent message in an object
}
function OnEvent_ChatWndDestroyed(ChatWnd) {
delete mySentMessages[ChatWnd.Handle]; // delete the message from the object as it isn't needed anymore
}
/*
Use bEnabled to control whether or not you want the nudge to be sent.
When the user clicks the menu item to disable the script set bEnabled = false; and vice versa when they are enabling it.
*/
|
|
11-27-2008 02:29 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: Help - I'm new to scripting!
So, in the "on click" thing for enable and disable in the script menu, I need to put "bEnabled = [true/false]", right?
|
|
11-27-2008 07:37 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Help - I'm new to scripting!
quote: Originally posted by whiz
So, in the "on click" thing for enable and disable in the script menu, I need to put "bEnabled = [true/false]", right?
Yeah exactly. You want to change the variable so that it will disable the script internally.
|
|
11-27-2008 07:38 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: Help - I'm new to scripting!
Sorry - another question!
I'm trying this code on a simpler script, that displays toasts to the user regarding certain information, like sign-ins, name changes and so on.
Am I right in thinking that the menu items should be set like this:
jscript code: function OnEvent_MenuClicked(sMenuId)
{
if(sMenuId=="Enable")
{
var bEnabled = true;
var Message = "Toaster has just been enabled!";
Message = MsgPlus.RemoveFormatCodes(Message);
MsgPlus.DisplayToast("Toaster", Message);
Debug.Trace("Toaster | Enable");
}
if(sMenuId=="Disable")
{
var bEnabled = false;
var Message = "Toaster has just been disabled!";
Message = MsgPlus.RemoveFormatCodes(Message);
MsgPlus.DisplayToast("Toaster", Message);
Debug.Trace("Toaster | Disable");
}
}
And then each toast should be like this:
jscript code: function OnEvent_Signin(Email)
{
if(bEnabled=="true")
{
var Message = "You have been signed in.";
Message = MsgPlus.RemoveFormatCodes(Message);
MsgPlus.DisplayToast("Toaster", Message);
Debug.Trace("Toaster | UserSign-in");
}
}
|
|
12-07-2008 11:25 AM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Help - I'm new to scripting!
That'll work, but not in the way you'd expect it. Therefore, in your OnEvent_Signin function, use
jscript code: if(bEnabled)
since the way you do it now is by comparing it to the literal message "true" rather than the boolean value true.
|
|
12-07-2008 11:29 AM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|