callbacks and methods
by rennie moffat · in Torque Game Builder · 08/12/2009 (2:46 pm) · 18 replies
Just need help in clarifying something.
function doThis::onMouseDown()
{
%obj.setDamping(0.25);
}
A. this code should be legible right?
B. function doThis is a function? this can be anything I want. Jump, fly, drive, evaporate. Correct?
C. onMouseDown, this is a callback and certain things in Torque have certian predetermined callbacks.
D. %obj.setDamping(), this is a method and again, like the call backs certain things like a scene2dObject have certain methods, but I can mix and match my methods for any call back?
Im getting it right?
function doThis::onMouseDown()
{
%obj.setDamping(0.25);
}
A. this code should be legible right?
B. function doThis is a function? this can be anything I want. Jump, fly, drive, evaporate. Correct?
C. onMouseDown, this is a callback and certain things in Torque have certian predetermined callbacks.
D. %obj.setDamping(), this is a method and again, like the call backs certain things like a scene2dObject have certain methods, but I can mix and match my methods for any call back?
Im getting it right?
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
so doThis, would be in the doThis.cs?
but the basic formula to a function, it's main ingredients if you will are...
class::callback
{
method
}
and yes, I agree regaurding the tuts. It's just that I have ideas for these games in which I have already figured out what mut be done in order to make a cool game. How it is controlled, what happens etc. Its just the actual coding, so i get it, how it must work, just implementing it that gets me. I think I should to, I am just very excited and think, "ooo I might get it this time".
But yeah.
08/12/2009 (3:59 pm)
so doThis is a class. so doThis, would be in the doThis.cs?
but the basic formula to a function, it's main ingredients if you will are...
class::callback
{
method
}
and yes, I agree regaurding the tuts. It's just that I have ideas for these games in which I have already figured out what mut be done in order to make a cool game. How it is controlled, what happens etc. Its just the actual coding, so i get it, how it must work, just implementing it that gets me. I think I should to, I am just very excited and think, "ooo I might get it this time".
But yeah.
#3
class::functionName(Function_arguments)
{
Function_body
}
Classes can be separated into different script files but they don't need to be. Most people do for issues of clarity but there's nothing preventing you from having any number of classes in a .cs file and calling the file anything you want.
Callbacks are special types of functions that are triggered when certain events happen. They have a set number of arguments and format and you can add the code you want in the function body to do whatever you want to happen on that event.
08/12/2009 (4:09 pm)
Torque follows the normal object orient programing format which isclass::functionName(Function_arguments)
{
Function_body
}
Classes can be separated into different script files but they don't need to be. Most people do for issues of clarity but there's nothing preventing you from having any number of classes in a .cs file and calling the file anything you want.
Callbacks are special types of functions that are triggered when certain events happen. They have a set number of arguments and format and you can add the code you want in the function body to do whatever you want to happen on that event.
#4
08/13/2009 (6:34 am)
Quote:QFT man... QFT.
Rennie, it's good to ask questions and no one here really minds answering them but you really need to go back and do a few tutorials. You're not grasping the general concepts of how torque works. You're not at a level where you can ask the right questions to help your understanding yet. A few days of working through the tutorials (I recommend the fish tutorial) will improve your understanding more than asking questions.
Quote:not necesarily. you can put all your code into a single file if you want, but for readability and organization, you break certain code into several files, with sound names, that will help you go thru your code fast, when needed.
so doThis is a class.
so doThis, would be in the doThis.cs?
#5
and as far as i remember, oyu can only create callbacks on your own, when you have the SC License. just in case the question pops up.
08/13/2009 (6:36 am)
Quote:
Callbacks are special types of functions that are triggered when certain events happen. They have a set number of arguments and format and you can add the code you want in the function body to do whatever you want to happen on that event.
and as far as i remember, oyu can only create callbacks on your own, when you have the SC License. just in case the question pops up.
#9
I just took your little link Patrick and it does not turn up what QFT in this instance means so please, all respect due, step aside.
I read the lyrics watched the vid. Not very optimistic, kinda miserable. Not where Im going. Anyhow, take her easy boys, will be in touch.
08/13/2009 (9:43 am)
Well smart ass. I just took your little link Patrick and it does not turn up what QFT in this instance means so please, all respect due, step aside.
I read the lyrics watched the vid. Not very optimistic, kinda miserable. Not where Im going. Anyhow, take her easy boys, will be in touch.
#10
later...
08/13/2009 (9:54 am)
I wasn't trying to insult you, but simply illustrate that if you look for answers to your questions, you will find them. If you can't see the humor in how it was presented, then that's on you.later...
#11
08/13/2009 (9:59 am)
no problem, well i kind of took it as an insult so thats on you. I am a very humorous guy, cant you tell that by now? anyhow, just learning still and again thanks for all the help thus far.
#12
a function name. is it predetermined?
ex, obviously "onWorldLimit" is, but what about more abstract things like "spawn" and "explode"?
The reason I ask is because I have discovered a page(http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide) with all object methods and callbacks ex. onMouseDown, rotateTo... they all seem to be very physics based, very exact. But what about more abstract things like explode or fireGun? These seem to me to be a little more abstract. Are ones like these simply made up, as in can be anything I want Ex. "fly", I simply just define the terms later in code?
Just a little philosophical question for me. Hope it doesn't hurt.
08/13/2009 (10:12 am)
while I am here, and if you dont want to answer fine. But just in my thinking here, this would help. a function name. is it predetermined?
ex, obviously "onWorldLimit" is, but what about more abstract things like "spawn" and "explode"?
The reason I ask is because I have discovered a page(http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide) with all object methods and callbacks ex. onMouseDown, rotateTo... they all seem to be very physics based, very exact. But what about more abstract things like explode or fireGun? These seem to me to be a little more abstract. Are ones like these simply made up, as in can be anything I want Ex. "fly", I simply just define the terms later in code?
Just a little philosophical question for me. Hope it doesn't hurt.
#13
lolz... (even harder)
dude, QFT stands for "Quote for Truth"... at least, in the sense i was presenting it.
08/13/2009 (10:18 am)
Quote:lolz....
Quest For Tanelorn a song of Blind Guardian
:P
Quote:
hmmm, let's see.... QFT
lolz... (even harder)
dude, QFT stands for "Quote for Truth"... at least, in the sense i was presenting it.
#14
08/13/2009 (10:20 am)
oh ok, well thats better than that lame ass song. Nerdsville indeed, no disrespect to all Dungeon and Drangoners. But thats what that song reminds me of. I like your QFT way better.
#15
i think, you should, AGAIN go and read the reference guide... all of the Torque stock functions are there. if you dont find a function name in it, then its a custom function.
to put it simply:
- onWorldLimit, onCollision and allthat, are callbacks (a special type of functions, if you like, that comes with stock TGB).
- mCeil, mFloor, mSin, etc, are special stock math functions on TGB
- setLinearVelocity, setAtRest etc, are stock methods (functions) of sceneObjects in TGB.
- fireBullets, Explode and so on, are custom user fnuctions (the ones you create specifically for the logic of your game).
like i said, if you read the reference guide, and make a couple tuts on your own, trust me, you wouldnt be asking such questions, since you'd figure it out right away.
08/13/2009 (10:26 am)
Quote:
a function name. is it predetermined?
ex, obviously "onWorldLimit" is, but what about more abstract things like "spawn" and "explode"?
The reason I ask is because I have discovered a page(http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide) with all object methods and callbacks ex. onMouseDown, rotateTo... they all seem to be very physics based, very exact. But what about more abstract things like explode or fireGun? These seem to me to be a little more abstract. Are ones like these simply made up, as in can be anything I want Ex. "fly", I simply just define the terms later in code?
Just a little philosophical question for me. Hope it doesn't hurt.
i think, you should, AGAIN go and read the reference guide... all of the Torque stock functions are there. if you dont find a function name in it, then its a custom function.
to put it simply:
- onWorldLimit, onCollision and allthat, are callbacks (a special type of functions, if you like, that comes with stock TGB).
- mCeil, mFloor, mSin, etc, are special stock math functions on TGB
- setLinearVelocity, setAtRest etc, are stock methods (functions) of sceneObjects in TGB.
- fireBullets, Explode and so on, are custom user fnuctions (the ones you create specifically for the logic of your game).
like i said, if you read the reference guide, and make a couple tuts on your own, trust me, you wouldnt be asking such questions, since you'd figure it out right away.
#16
08/13/2009 (10:28 am)
cool I am doing player movement tut now. but that helps for the future use, thanks.
#17
anyway, dont take things too seriously here, when it comes to comments appart from your original questions, ppl here are not into flaming wars, but sometimes satirical, or misleading commentaries can come up as easily as it can be.
08/13/2009 (10:34 am)
Quote:lol ... i've heard the song, but its been awhile since last time, so its not like i remember how it goes.
oh ok, well thats better than that lame ass song. Nerdsville indeed, no disrespect to all Dungeon and Drangoners. But thats what that song reminds me of. I like your QFT way better.
anyway, dont take things too seriously here, when it comes to comments appart from your original questions, ppl here are not into flaming wars, but sometimes satirical, or misleading commentaries can come up as easily as it can be.
#18
I call this "time manipulation".
08/13/2009 (10:43 am)
yah emails can be misleading as they tone can be misread. Its one thing if someone says something to you in an instant, but over even 10 minutes difference, moods may change etc. I call this "time manipulation".
Nate Gertsch
B) The way that you have declared it, doThis is an class and you are attempting to use a callback or function called onMouseDown().
C) Think of callbacks as functions that are triggered not when you call them but when certain events occur. They always have predetermined arguments that are automatically passed into the function.
D) Certain torque objects have predefined functions but it sounds like you're thinking that methods and functions are two different things when they are simply two different ways of saying the same thing in this case.
Rennie, it's good to ask questions and no one here really minds answering them but you really need to go back and do a few tutorials. You're not grasping the general concepts of how torque works. You're not at a level where you can ask the right questions to help your understanding yet. A few days of working through the tutorials (I recommend the fish tutorial) will improve your understanding more than asking questions.