OOP Need help getting methods to return objects.I am working on a class of vectors in JSL. I would like to have a method that would return a normalized version of the vector. Below is my script and error message. Thanks!
Clear Log();
Clear Globals();
Define Class(
"vector",
x = 0;
y = 0;
z = 0;
_init_ = Method( {a, b, c = 0},
x = a;
y = b;
z = c;
);
_show_ = Method( {},
Return( x, y, z )
);
mag = Method( {},
magnitude = Sqrt( x ^ 2 + y ^ 2 + z ^ 2 )
);
normalize = Method( {},
nv = vector(0,0,0);
length = Sqrt( x ^ 2 + y ^ 2 + z ^ 2 );
show(length);
nv:x = x / length;
nv:y = y / length;
nv:z = z / length;
nv;
);
);
bob = New Object( vector( 4, 2 ) );
Show( bob );
bob<<NORMALIZE></NORMALIZE>Name Unresolved: vector in access or evaluation of 'vector' , vector( 0, 0, 0 )
Re: OOP Need help getting methods to return objects.I am a novice when it comes to classes in general and JMP Classes. This works:
Clear Log();
Clear Globals();
Define Class(
"vector",
x = 0;
y = 0;
z = 0;
_init_ = Method( {a, b, c = 0},
x = a;
y = b;
z = c;
);
_show_ = Method( {},
Return( x, y, z )
);
mag = Method( {},
magnitude = Sqrt( x ^ 2 + y ^ 2 + z ^ 2 )
);
normalize = Method( {},
nv = [0,0,0];
length = Sqrt( x ^ 2 + y ^ 2 + z ^ 2 );
show(length);
nv[1] = x / length;
nv[2] = y / length;
nv[3] = z / length;
Print(char(nv));
nv;
);
);
bob = New Object( vector( 4, 2 ) );
Show( bob );
bob = bob:normalize();
show(bob);
Ther is a method to pass self. I suggest the JMP Scripting Guide and searching this website for Classes.
Re: OOP Need help getting methods to return objects.Georgia,
Thanks for your reply. I found the "clone" message for objects that I can use to create a copy of the object and then normalize it. I will keep looking around and see if I can find anything on how to return objects from methods directly like they do in the "complex" class example.
John