Author Topic: Please look over my script  (Read 1034 times)

Please see if i screwed something up, im trying to do right click then gives you velocity
Code: [Select]
//directionalJet Player
datablock PlayerData(PlayerdirectionalJet : PlayerStandardArmor)
{

minJetEnergy = 0;
jetEnergyDrain = 0;
canJet = 0;

uiName = "directionalJet Player";
showEnergyBar = false;

runForce = 30 * 30;
runEnergyDrain = 0;
minRunEnergy = 0;
maxForwardSpeed = 10;
maxBackwardSpeed = 8;
maxSideSpeed = 4;

jumpForce = 30 * 30;

maxForwardCrouchSpeed = 8;
maxBackwardCrouchSpeed = 6;
maxSideCrouchSpeed = 5;

runSurfaceAngle = 55;
jumpSufaceAngle = 35;
};

package directionaljet
{
function Armor::onTrigger(%this, %player, %slot, %val)
{
parent::onTrigger(%this, %player, %slot, %val);
if(%slot == 4 &&%val == 1)
%player.directionalJet(1);
}
else
if(%slot == 4 &&%val == 0)
{
%player.directionalJet(0);
}
}
};
activatePackage(directionalJet);
function player::directionalJet(%this,%bool)
{
cancel(%this.djl);
{
if(%bool)
%this.addVelocity(%this.getEyeVector());
%this.djl = %this.schedule(1,directionalJet,%bool);
}
else
{
return 0;
}
}

In armor::ontrigger
missing an opening bracket for the if
else if should be one line

in directionaljet:
random brackets after cancel
missing brackets after the if

Logically, your directionaljet function won't work properly
Drop the %bool argument and anything referencing it, and just do

cancel(...);
%this.addvelocity(...);
schedule(...);


and then change the directionaljet(0) call to a cancel

Also, don't use acronyms (djl) for variable names unless it's very obvious what it means

Code: [Select]
//directionalJet Player
datablock PlayerData(PlayerdirectionalJet : PlayerStandardArmor)
{

minJetEnergy = 0;
jetEnergyDrain = 0;
canJet = 0;

uiName = "directionalJet Player";
showEnergyBar = false;

runForce = 30 * 30;
runEnergyDrain = 0;
minRunEnergy = 0;
maxForwardSpeed = 10;
maxBackwardSpeed = 8;
maxSideSpeed = 4;

jumpForce = 30 * 30;

maxForwardCrouchSpeed = 8;
maxBackwardCrouchSpeed = 6;
maxSideCrouchSpeed = 5;

runSurfaceAngle = 55;
jumpSufaceAngle = 35;
};

package directionaljet
{
function Armor::onTrigger(%this, %player, %slot, %val)
{
parent::onTrigger(%this, %player, %slot, %val);
if(%slot == 4 &&%val == 1)
%player.directionalJet(1);
}
else
if(%slot == 4 &&%val == 0)
{
%player.directionalJet(0);
}
}
};
activatePackage(directionalJet);
function player::directionalJet(%this)
{
cancel(...);
{
if(...)
%this.addVelocity(...);
%this = %this.schedule(...);
}
else
{
return 0;
}
}
Im having trouble understanding the brackets

When you create an opening bracket "{", you always need a closing bracket "}".

Example:

function hi(%hi)
{
   if(%hallo)
   {
      if(%hallo)
      {
         if(%hallo)
         {
            if(%hallo)
            {
               while(false)
               {
                  %hi = "hi there";
               }
            }
         }
      }
   }
}

Also, every single player type will be able to directional jet, as you don't check if their playertype is your specific one.

you still have
random brackets after cancel
missing brackets after the if
%bool argument and anything referencing it [the argument in the function call]

When I said
and just do

cancel(...);
%this.addvelocity(...);
schedule(...);


I really did mean just do. Meaning the directionaljet function should only be those three lines.
And those ellipsis are there because I didn't feel like copying the entire contents of the code. It's psuedocode.  You're not supposed to just paste that in

When you create an opening bracket "{", you always need a closing bracket "}".
Example:
Technically in that case you don't. But it's better to learn to always put them in until you know what you're doing

Technically in that case you don't. But it's better to learn to always put them in until you know what you're doing
Yeah, otherwise its:
function hi(%hi)
{
   if(%hallo)
      if(%hallo)
         if(%hallo)
            if(%hallo)
               while(false)
               {
                  %hi = "hi there";
               }
}

Even the while loop brackets aren't necessary in that case
But as I said, best to leave brackets in until you know what you're doing, because without them, proper indentation is the only indication you have of what's going on

For clarity's sake since neither of you actually explained it: if the if statement doesn't have a bracket after it, it only encapsulates the following line.

So,
Code: [Select]
if(true == false)
    echo("The world is broken!");
else
    echo("The world is safe!");
echo("this will run anyway!");

This works for conditional statement lines, i.e. if, while, for.