Game Development Community

Need help with a code

by Quentin Headen · in Torque Game Engine · 06/03/2006 (1:53 pm) · 3 replies

In another forum thread, I asked how to mount wheels on a car in the game just like the buggy. A person submitted a post and gave me this code

Look for this datablock in you car script "WheeledVehicleTire"

"example" datablock WheeledVehicleTire(tankTire)

And the onAdd part as well this is for a wheeled tank of mine

function tank::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,tankTire);
%obj.setWheelSpring(%i,tankSpring);
%obj.setWheelPowered(%i,false);
}



He did well on telling me what the code is, but I need someone to break it down for me please. I know I am a pest, but I am also a BEGINNER!!. I know Absolutely Positively nothing about programming. Please guys help me.

About the author

Just your average programmer who tries to finish the projects he starts. :) I am currently focused on creating games with Torque engines. My website is http://phaseshiftsoftware.com


#1
06/03/2006 (3:29 pm)
Lol Quentin.

just what are you asking?

break it down?
how broken down do you need it?
I think bud you need to study some more programming if you want to be able to do this stuff.
having someone "break this down" for you is not going to help much.

lets break it down a bit for ya.

function tank::onAdd.....
this is a function a function is a place to do stuff.
this function belongs to the "tank" object.
the tank object when added to the game by either the editor or on startup or some other mechanism has
this function called on it. so somewhere you can see something like this:
tank.onAdd();
... dont expect to find that exact line it is in the source and it is going to be more dynamic than tank.onAdd

something more like newObject.OnAdd(); ...

when the tank is added and this function is called the code in this function is executed.

the parameters passed to the function %this and %obj can be used within the function.
%this is the actual tank (i think)
%obj is the datablock (i think)
here we are going to set the wheels springs and if the wheel gets power from the transmission.

this code is what I call self documenting :)
the function names and objects used should intuitively tell you what is happening.

setWheelTire(...)
what do you think this function does?
it does just what is says on the tin. it sets the wheel tire for this "tank" object.
when seeing a variable used like this:
%obj.setWheelTire(%i,tankTire);
see tankTire?
that is a variable you will have to look up and find .. so do a search in the script code to find the definition of this tire object.

tankSpring.. same scenario.
analyze the code surrounding all the objects related to your task.

if you really want to program. you should choose a language and study it.
once you have a grasp on it and programming in general you will be able to go alot farther with this.
#2
06/03/2006 (4:40 pm)
Thanks a bunch.
#3
06/04/2006 (5:49 am)
Just a note, %this might be the tank, but there is no garentuee, as someone could call it with another parameter, the same goes for %obj. So if you are depending on the type make sure you got the right object type, before you do anything with it, and if it's not give a proper error.