TGE seems odd to me, any others?
by Anthony C · in General Discussion · 05/15/2007 (9:30 am) · 4 replies
Hey all, ive been writing code for several years, so im used to seeing most of everything i have seen in torque so far, but one thing has been frustrating me a lot..
i'll see something like... function name(%this, %obj, %dist, %amount), and then in the actual function definition, not all of the parameters will be used
i *should* mention that this is my first 3d programming experience in quite a while so maybe i forgot some stuff, but it looks very weird coming from a language such as c++.
another thing i have a question about it the documentation for torque, it seems small lol. I actually just got done looking for some tutorials, as the book isnt very clear when they build a project
i'll see something like... function name(%this, %obj, %dist, %amount), and then in the actual function definition, not all of the parameters will be used
i *should* mention that this is my first 3d programming experience in quite a while so maybe i forgot some stuff, but it looks very weird coming from a language such as c++.
another thing i have a question about it the documentation for torque, it seems small lol. I actually just got done looking for some tutorials, as the book isnt very clear when they build a project
About the author
#2
05/16/2007 (10:49 am)
Ah, well that explains part of it. there have been other times though with paramets that arent "this" that arent used, how should i interpret it then?
#3
05/16/2007 (11:07 am)
www.garagegames.com/docs/tge/general/ch05s02.php Search for: 'Console Methods' on that page.
#4
I think of functions that have been defined with object scope as 'methods'.
In the example above, the method 'spawn' of the object $player is being called. Since this is a method call rather than a function call, the magic of Torque Script makes the first parameter the object in question.
You make something a method by scoping it with ::
A further convention is that %datablock is used instead of %this if it is a datablock method. You could use %fred as the first parameter if you wanted; it really does not matter.
Console functions (defined in C++ code) will give you an error if not called in one of the ways the author predicted; they can have variable length parameter lists and the engine checks for this when interfacing between Torque Script and C++. Checks of this kind are not performed when callee and caller are Torque Script functions/methods; you get the parameters that you are given and the others will get default values.
The answer to your question is that you may have seen examples of Torque Script functions where the author was being lazy i.e. not supplying all the parameters, or was calling a Console function that has multiple signature flavours, or the first parameter had an unconventional name.
I hope this helps your understanding a little.
Good luck.
05/16/2007 (11:14 am)
The fact that the parameter is called %this is just a convention.I think of functions that have been defined with object scope as 'methods'.
In the example above, the method 'spawn' of the object $player is being called. Since this is a method call rather than a function call, the magic of Torque Script makes the first parameter the object in question.
You make something a method by scoping it with ::
A further convention is that %datablock is used instead of %this if it is a datablock method. You could use %fred as the first parameter if you wanted; it really does not matter.
Console functions (defined in C++ code) will give you an error if not called in one of the ways the author predicted; they can have variable length parameter lists and the engine checks for this when interfacing between Torque Script and C++. Checks of this kind are not performed when callee and caller are Torque Script functions/methods; you get the parameters that you are given and the others will get default values.
The answer to your question is that you may have seen examples of Torque Script functions where the author was being lazy i.e. not supplying all the parameters, or was calling a Console function that has multiple signature flavours, or the first parameter had an unconventional name.
I hope this helps your understanding a little.
Good luck.
Torque 3D Owner Tom Perry
%player.spawn(%pos); function player::spawn(%this,%pos) { // some stuff in here with player and position }In the player::spawn funciton, the %this parameter refers to the %player that called the function.
Try looking on TDN for more documentation, there is quite a lot but its in various places and in no particular order!