%this and %obj variables.???
by Alfred CLUMSON · in Technical Issues · 02/02/2005 (6:46 pm) · 9 replies
Hello !
I am new to torque and I'm a little bit confused about the use of %this and
%obj variables in objects function definitions .it seams to me like they all call functions from the same source .Can anybody give me a clear idea on how to call datablocks functions and parents functions(in case the datablock is derived from a parent ) ?
Thanks
I am new to torque and I'm a little bit confused about the use of %this and
%obj variables in objects function definitions .it seams to me like they all call functions from the same source .Can anybody give me a clear idea on how to call datablocks functions and parents functions(in case the datablock is derived from a parent ) ?
Thanks
About the author
#2
02/02/2005 (9:52 pm)
Anthony is correct, however note that the function defines %this and %obj, they are not intrinsicly defined variables in TorqueScript.
#3
02/02/2005 (10:23 pm)
I take good note .Thank you guys.
#5
Here is a "writeClass()" function to the "JournalDemo" namespace... now the JournalDemo is a gui, so it attaches this function to its namespace... to perform this function in script I would type
"JournalDemo.writeClass("entry", "name", "Quest Person 4");"
now since its in a namespace, designated by the "::" when I call this function the first variable is itself, which would be the JournalDemo object... that way I can then type
"%this.writeProperty(%class, %property);"
because this function is a JournalDemo namespace function also... its the same as typing
"JournalDemo.writeProperty(%class, %property);"
this way If I ever rename the GUI.. say to Journal... I won't have to replace all the "JournalDemo." functions.. since they are %this, I would just have to change the function calls... "JournalDemo::"...
hope this helps
02/07/2005 (12:29 pm)
Lately I've been working on a journal system... here is a function from it (maybe can show some good use for this as well)Here is a "writeClass()" function to the "JournalDemo" namespace... now the JournalDemo is a gui, so it attaches this function to its namespace... to perform this function in script I would type
"JournalDemo.writeClass("entry", "name", "Quest Person 4");"
function JournalDemo::writeClass(%this, %class, %property, %value)
{
$journalMainTags[$mainTagCount] = %class;
$mainTagCount++;
%this.writeProperty(%class, %property);
%this.addInstance(%class, %property, %value);
$journalArrayCount++;
}now since its in a namespace, designated by the "::" when I call this function the first variable is itself, which would be the JournalDemo object... that way I can then type
"%this.writeProperty(%class, %property);"
because this function is a JournalDemo namespace function also... its the same as typing
"JournalDemo.writeProperty(%class, %property);"
this way If I ever rename the GUI.. say to Journal... I won't have to replace all the "JournalDemo." functions.. since they are %this, I would just have to change the function calls... "JournalDemo::"...
hope this helps
#6
%this and %obj are more standard practice then necessity right?
I mean it could just be %whatever and %poostick right??
02/08/2005 (5:29 am)
Just to reaffirm what you are saying pat...%this and %obj are more standard practice then necessity right?
I mean it could just be %whatever and %poostick right??
#7
02/08/2005 (6:18 am)
@charlie: damn, you read my scripts!
#8
02/08/2005 (8:06 am)
Got to watch out with the %poostick variable... quite a powerful thing ;)
#9
02/08/2005 (10:17 am)
You are correct, Charlie.
Associate Anthony Rosenbaum