echo and its purpose
by rennie moffat · in Torque Game Builder · 11/27/2009 (1:47 pm) · 11 replies
Hi forgive the newbie to the max question but I am going back and studying Torque script from the beginning, Obviously echo is used quite a bit and can be a large help in debugging. But what I am asking specifically is this. What does it do? Read on, does it simply live inside X function or X script, when placed, and calls for whatever is inside it's (), so echo(%count) will simply call to count, giving continual updates to the computer the status of count?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
In the above example, looks like someone was just using echo() to do some simple debugging or to figure out some nuance of TorqueScript. You could remove them if you wanted.
11/27/2009 (3:49 pm)
"Echo()" just prints output to Torque's console, just like "printf()" prints output to the command prompt in C. If you open up the console and type "myGuy.getId()", you won't see anything returned. The command executed, but you didn't redirect the output to the console. So now type "echo(myGuy.getId())" and you'll see the ID printed on the next line (if myGuy actually exists).In the above example, looks like someone was just using echo() to do some simple debugging or to figure out some nuance of TorqueScript. You could remove them if you wanted.
#3
So lets just say myGuy is = $player_name as above. Will it return $player_name or something else, some other type of id.
And yah about the removal, its just from the "Beginnings of Torque Teachings" or something I am just trying to get a better hold on the basic fundamentals before I make major steps.
Also, how is it used, echos are calls just to see if something exists, or running properly?
11/27/2009 (4:00 pm)
Quote:
So now type "echo(myGuy.getId())" and you'll see the ID printed on the next line (if myGuy actually exists).
So lets just say myGuy is = $player_name as above. Will it return $player_name or something else, some other type of id.
And yah about the removal, its just from the "Beginnings of Torque Teachings" or something I am just trying to get a better hold on the basic fundamentals before I make major steps.
Also, how is it used, echos are calls just to see if something exists, or running properly?
#4
Echos print stuff. It doesn't have any other hidden functionality. To what purpose you want it is up to you. You echo something, that something appears on the console. That's it.
11/27/2009 (4:23 pm)
Echo exists to print text. In the case of:echo(myGuy.getId());it prints (to the console or console log) whatever the method getId() returns.
Echos print stuff. It doesn't have any other hidden functionality. To what purpose you want it is up to you. You echo something, that something appears on the console. That's it.
#5
myGuy.position;
$player_name.position;
$player_id.position;
4287.position;
So basically, the example is trying to show you that you can access an object's methods and member variables by either directly using that object's name or id, or using variables that resolve to that object's name or id.
11/27/2009 (4:30 pm)
Every object has a unique id associated with it. Its just an integer value. If you echo an id, you'll get something like "4287". You can refer to an object either by its name or by its id. In your above example, lets assume that myGuy's id is 4287. In that case, all of these statements are the same...myGuy.position;
$player_name.position;
$player_id.position;
4287.position;
So basically, the example is trying to show you that you can access an object's methods and member variables by either directly using that object's name or id, or using variables that resolve to that object's name or id.
#6
11/27/2009 (4:33 pm)
ok so in this case myGuy, $player_name, $player_id and 4287 are all interchangeable?
#7
11/27/2009 (5:15 pm)
That is correct. But it is important to note that the id is set by the engine at runtime, so myGuy's id will not always be 4287. Next time, his id may be 3922, for example. So don't hardcode id's into your scripts. :)
#8
11/27/2009 (5:31 pm)
hmm or at all?
#9
what is the proper way to id the worldPos?
11/28/2009 (12:47 am)
so regarding "tagging" or identifying objects. I have a question...function sceneWindow::onMouseDown(%this, %worldPos)
{
sceneWindow.worldPos
%this.worldPos
%worldPos
}what is the proper way to id the worldPos?
#10
I've noticed a trend in your programming. You constantly call functions, or variables, or just values, without capturing their contents.
For example, in your function, all three lines do the equivalent of .. nothing, because you do not assign the values (assuming they exist) to any variable, or data structure.
1. function sceneWindow::onMouseDown(%this, %worldPos)
2. {
3. sceneWindow.worldPos
4. %this.worldPos
5. %worldPos
6. }
First of all, i'm not sure what you think line 3 is doing, but its probably not doing what you expect. The way you have it, worldPos must be a data memeber of the sceneWindow class, NOT the %worldPos you passed into the function. if you wanted to access the contents of the %worldPos variable, simply use %worldPos. this sentiment goes equally true for line 4.
Now its important to see that this code is still fundamentally wrong. Assuming all the variables names are valid, you'd still just be doing something equivalent the following:
1. function sceneWindow::onMouseDown(%this, %worldPos)
2. {
3. "45 55";
4. "100 250";
5. "2.31 3.1415";
6. }
Those numbers are all random, but they make my point. Do you expect this code to do anything? Of course not! You need to assign, capture, select (whatever word you want) those numbers!
i tried to make sense of your function, but i really dot know what you're trying to accomplish, so i made a different example.
function player::setCoordinates(inputX, inputY)
{
%this.xLocation = inputX;
%this.yLocation = inputY;
return;
}
This function will only work if i call it on an object of the player class. the player class must have some attributes xLocation and yLocation. The inputX, and inputY are parameters which are 'passed into' the function as its arguments wherever it is called.
this function would be called like this
myPlayer.setLocation("55", "45");
where myPlayer is just an object of the player class.
This example may seem pretty trivial or dumb to you, if so i apologize, but i see a repeated lack of understanding of basic programming concepts in your posts.
To expand, i see a lot of posts where you have expectations of the code that simply are unrealistic. The code doesn't understand relationships between functions like 'setPosition()' and variables like worldPos. It will not bridge the gaps for you. You keep asking what functions 'purposes' are, such as the basic Echo() statement, but the answer is simply that the purposes are whatever the programmer tasks it to do.
i could call 1000 different functions that all use complex algorithms to sort and unsort an array of a million numbers. every second function would be undo'ing the work of the previous one, and i'd eventually end up with an useless unsorted array of integers! Just because i made functions that work (and work together) doesn't mean i solved any problem.
I hear often that programming is an 'art' and thats certainly true to a degree, but i really think it is 90% science. However, just like the more complicated sciences, one requires a special brain, a certain way of thinking, and a lot of critical thinking and problem solving skills to succeed.
Programming languages are powerful, but they're only as useful as the mind of their user.
12/01/2009 (3:25 am)
rennie, i'm not sure what you're trying to accomplish with your onMouseDown method there, but i have a hard time believing it does .. anything productive. I've noticed a trend in your programming. You constantly call functions, or variables, or just values, without capturing their contents.
For example, in your function, all three lines do the equivalent of .. nothing, because you do not assign the values (assuming they exist) to any variable, or data structure.
1. function sceneWindow::onMouseDown(%this, %worldPos)
2. {
3. sceneWindow.worldPos
4. %this.worldPos
5. %worldPos
6. }
First of all, i'm not sure what you think line 3 is doing, but its probably not doing what you expect. The way you have it, worldPos must be a data memeber of the sceneWindow class, NOT the %worldPos you passed into the function. if you wanted to access the contents of the %worldPos variable, simply use %worldPos. this sentiment goes equally true for line 4.
Now its important to see that this code is still fundamentally wrong. Assuming all the variables names are valid, you'd still just be doing something equivalent the following:
1. function sceneWindow::onMouseDown(%this, %worldPos)
2. {
3. "45 55";
4. "100 250";
5. "2.31 3.1415";
6. }
Those numbers are all random, but they make my point. Do you expect this code to do anything? Of course not! You need to assign, capture, select (whatever word you want) those numbers!
i tried to make sense of your function, but i really dot know what you're trying to accomplish, so i made a different example.
function player::setCoordinates(inputX, inputY)
{
%this.xLocation = inputX;
%this.yLocation = inputY;
return;
}
This function will only work if i call it on an object of the player class. the player class must have some attributes xLocation and yLocation. The inputX, and inputY are parameters which are 'passed into' the function as its arguments wherever it is called.
this function would be called like this
myPlayer.setLocation("55", "45");
where myPlayer is just an object of the player class.
This example may seem pretty trivial or dumb to you, if so i apologize, but i see a repeated lack of understanding of basic programming concepts in your posts.
To expand, i see a lot of posts where you have expectations of the code that simply are unrealistic. The code doesn't understand relationships between functions like 'setPosition()' and variables like worldPos. It will not bridge the gaps for you. You keep asking what functions 'purposes' are, such as the basic Echo() statement, but the answer is simply that the purposes are whatever the programmer tasks it to do.
i could call 1000 different functions that all use complex algorithms to sort and unsort an array of a million numbers. every second function would be undo'ing the work of the previous one, and i'd eventually end up with an useless unsorted array of integers! Just because i made functions that work (and work together) doesn't mean i solved any problem.
I hear often that programming is an 'art' and thats certainly true to a degree, but i really think it is 90% science. However, just like the more complicated sciences, one requires a special brain, a certain way of thinking, and a lot of critical thinking and problem solving skills to succeed.
Programming languages are powerful, but they're only as useful as the mind of their user.
#11
so before I go into replying any more of your kind reply you misread the first bit. perhaps I should have made that more clear but with a scenewindow2d class I was wondering (at teh time) how to best call worldPos.
so in
dont worry I am not totally inept.
12/01/2009 (11:56 am)
Dude, you have misread this quote. so before I go into replying any more of your kind reply you misread the first bit. perhaps I should have made that more clear but with a scenewindow2d class I was wondering (at teh time) how to best call worldPos.
so in
sceneWindow2d::onMouseDown(this, %worldPos)
{
///should I call %worldPos as...
%worldPos = %this.thing;
///or..
scenewindow2d.worldPos = %this.thing;
///or...
%this.worldPos
}dont worry I am not totally inept.
Torque Owner rennie moffat
Renman3000
in this example...
$player_name = "myGuy"; $player_id = $player_name.getID(); echo($player_name.position); echo($player_name.getID()); echo(myGuy.getid());what are the purpose of these echos?
two call, $player_name position, and getID, but why then does one exist for myGuy.getID? Why would the ID need to be called for two things which are equivalent?