OO On A Simple Scale (Eg. a Java style Private Global)
by Jacob S. · in Torque 3D Professional · 05/05/2010 (1:28 pm) · 1 replies
I'm always running into an annoyance with TS that I'd like CS files to behave more like a class/object. I've been spoiled the last few years ( or 8 ) when I started programing in Java.
Primarly I'd like just to be able to declare a non-global variable and have it persist longer than a single use.
For an (overly) simple example it would make computing distance more easily
Pseudo Example
Currently the only way that seems to work is to save it back to the object in C++ via console functions/methods or to declare a global which then is the same across all of torque or more importantly all of the instances of that class (AIPlayer type classes atm).
I guess what I want is the equivalent of a Java Private Global.
Can anyone point me in the right direction, I found a tutorial from TGA 1.2, but I'm hoping for something this simple there is something for T3D or atleast TGEA that I can update more easily.
Thanks.
Primarly I'd like just to be able to declare a non-global variable and have it persist longer than a single use.
For an (overly) simple example it would make computing distance more easily
Pseudo Example
%IWantToLive = "" (Declared outside of a function)
(Other functions)
function playGui::Distance(%this, %pos, %start, %ray){
// find end of search vector
%ray = VectorScale(%ray, 2000);
%end = VectorAdd(%start, %ray);
%searchMasks = $TypeMasks::PlayerObjectType ;
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
if( %scanTarg ) {
%selected = getWords(%scanTarg, 0, 0);
}
if(!%IWantToLive $= "") {
%distance = sqrt((%selected.x - %IWantToLive.x)^2 + (%selected.y - %IWantToLive.y)^2)
echo(%distance);
}
IWantToLive = %selected;
}Currently the only way that seems to work is to save it back to the object in C++ via console functions/methods or to declare a global which then is the same across all of torque or more importantly all of the instances of that class (AIPlayer type classes atm).
I guess what I want is the equivalent of a Java Private Global.
Can anyone point me in the right direction, I found a tutorial from TGA 1.2, but I'm hoping for something this simple there is something for T3D or atleast TGEA that I can update more easily.
Thanks.
Torque 3D Owner Matt Kronyak
RealmSource LLC
In your example you could simply do:
%this.IWantToLive = %select;
and the IWantToLive property will become part of playGui.
There is also a class called ScriptObject which can be used to encapsulate more complex data and used in a bunch of different ways.
You can assign any object as a property to any object dynamically in Torque script.