Script Classes - 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: Script Classes (/showthread.php?tid=75949)
Script Classes by Toneo on 07-08-2007 at 07:52 AM
I have a problem with classes in my scripts.
code: class myClass {
// code here...
}
Apart from that, there's just the OnEvent_Initialize and Uninitialize functions.
I don't know where to put my class code, and whenever it runs it is stopped. I look in the script debugger, and it has syntax error on the line that I have typed class myClass.
What's wrong?
RE: Script Classes by felipEx on 07-08-2007 at 08:39 AM
it works fine here:
code: var MyClass = {
"MyVar" : new String(),
"MyVar2" : new Boolean(),
"MyMethod" : function() {
MsgPlus.DisplayToast("", "=]");
}
}
function OnEvent_Initialize(MessengerStart)
{
var a = MyClass;
var b = MyClass;
a.MyVar2 = false;
a.MyVar = " =] ";
Debug.Trace(a.MyVar);
Debug.Trace(a.MyVar2);
a.MyMethod();
b.MyMethod();
}
RE: Script Classes by Toneo on 07-08-2007 at 10:44 AM
I meant as in Objects. As in classes. So you'd define a class, and then say... var blob = new Car() or something like that.
But anyway, what you've said seems to be the same thing. Thanks
RE: Script Classes by Ezra on 07-08-2007 at 11:20 AM
@Toneo
To do it the way you want it you should make it like this:
code: function myClass(){
this.var1 = ""
this.var2 = ""
this.method = function() {
beep();
}
this.method2 = otherfunc;
}
var myobj = new myClass;
myClass.method()
function otherfunc(){
Messenger.DisplayToast(""", "");
}
You can also find all the info you need right here : MSDN Jscript Reference
RE: Script Classes by Toneo on 07-08-2007 at 11:22 AM
Ah, yes, I understand that now. Thanks.
RE: Script Classes by markee on 07-08-2007 at 02:47 PM
quote: Originally posted by felipEx
it works fine here:
code: var MyClass = {
"MyVar" : new String(),
"MyVar2" : new Boolean(),
"MyMethod" : function() {
MsgPlus.DisplayToast("", "=]");
}
}
function OnEvent_Initialize(MessengerStart)
{
var a = MyClass;
var b = MyClass;
a.MyVar2 = false;
a.MyVar = " =] ";
Debug.Trace(a.MyVar);
Debug.Trace(a.MyVar2);
a.MyMethod();
b.MyMethod();
}
Correct me if I'm wrong, but isn't that an array rather than a class? To do classes don't you need to use prototype (which doesn't work on pre-defined classes that Patchou makes accessible)?
RE: Script Classes by -dt- on 07-08-2007 at 03:00 PM
quote: Originally posted by markee
quote: Originally posted by felipEx
it works fine here:
code: var MyClass = {
"MyVar" : new String(),
"MyVar2" : new Boolean(),
"MyMethod" : function() {
MsgPlus.DisplayToast("", "=]");
}
}
function OnEvent_Initialize(MessengerStart)
{
var a = MyClass;
var b = MyClass;
a.MyVar2 = false;
a.MyVar = " =] ";
Debug.Trace(a.MyVar);
Debug.Trace(a.MyVar2);
a.MyMethod();
b.MyMethod();
}
Correct me if I'm wrong, but isn't that an array rather than a class? To do classes don't you need to use prototype (which doesn't work on pre-defined classes that Patchou makes accessible)?
no its just using the object, the prototype is so that you can share functions, properties over every instance of that object
|