quote:
Originally posted by Plan-1130
Global variables have to be defined before anything else, like shown in my example, you can't define global variables any other way AFAIK.
Global variables can be defined anywhere in the code as long as they are outside any function and before the code where you use them. Though usually not good practice, the next code is perfectly valid:
[code]function Hello() {
Debug.Trace(myglobalvariable);
}
var myglobalvariable = 'Hello';
function World() {
Debug.Trace('World');
}
Hello();
World();
quote:
Originally posted by Poki
Well, let me show you what my problem was, may be you figure it out.
I had....
var sEmails = new Array("mail1@hotmail.com","mail2@hotmail.com","mail3@hotmail.com");
var ContactoUno = Messenger.MyContacts.GetContact(sEmails[0]);
var ContactoDos = Messenger.MyContacts.GetContact(sEmails[1]);
var ContactoTres = Messenger.MyContacts.GetContact(sEmails[2]);
before any function, when I realised I needed global variables in order to be accessed by any function, but the fact was that I had to redefine ContactoUno, ContactoDos, ContactoTres y every function I wanted to use it because I'd get an error if I didn't...
So, they are global but need to be defined in every function? in that case the script worked indeed... or what else could be wrong?
All the variables you defined there are global already.
Your problem is that you don't have valid values defined to them when the script starts.
Scripts are started before objects like
Messenger are fully available. Thus when the script engine comes to
ContactoUno it tries to parse/execute those methods from the
Messenger object but they aren't available yet, hence the error.
That's exactly why you need to use events like
OnEvent_Initialize(bMessengerStart), or in the above case even better
OnEvent_SigninReady(sEmail).
Study the
Official Plus! Live Scripting Documentation and the
JScript 5.6 Documentation.