3: What is the [if then / else] syntax for torque? examples?
if(%var == %value)
{
//do stuff
}
else if(%var > %value)
{
//do other stuff
}
else
{
//do other other stuff
}
There are the three examples in one piece. To see all of the different operators, check out the file posted in this topic:
http://forum.blockland.us/index.php?topic=20754.0. That file contains much of the basic Torque syntax and functions.
If you are only calling one function with an if statement, you don't need brackets after it. Ex:
if(%var == %val)
return;
The else and else if works the same way:
if(%var == %val)
return;
else
//do something
4: Is it possible to manipulate things like the muzzle velocity var within the state system to have a weapon that changes (pressure/speed and grav of bullet) in response to a variable or a state.
I've never worked much with states, so I'm not sure how that works exactly. I do know that you can overwrite the fire function and create your own projectile(s). Ephialtes executed this well in his shotgun.
Here is the code:
function shotgunImage::onFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
%obj.playThread(2, shiftAway);
%projectile = %this.projectile;
%spread = 0.0015;
%shellcount = 3;
for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);
%p = new (BowImage.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
5: Is it possible to have a weapon use several different types of bullets that are predefined? How would one add another projectile, and have a separate firing command?
A) Yes, using code such as the one posted above.
B) You would need to make your own modification to the fire method.
C) I'm assuming you mean something like the spacebar as a separate firing command. You would need to overwrite the method Armor::onTrigger(%this,%obj,%slot,%val) and check what they're triggering by checking the %slot argument. I believe if %slot returns 2 it is the spacebar that was pressed, and 4 is right click. %val is whether the pressed the key down or released it (1 if pressed, 0 if released).
I hope that helps!