Advanced Script error(fixed)
by Cody Putzier · in Game Design and Creative Issues · 02/02/2012 (7:17 am) · 1 replies
I keep getting an advanced script error in this code i tried to write, it says the error occurs in the first if statement. any help would be appreciated
%gravpick = 0;
function Player::gravityControl() // control gravity key with the 'Q' button
{
if($pPlayer.falling)
{
if($pPlayer.getLinearVelocityY() == 0 && ($pPlayer.gravity == 0 || $pPlayer.gravity == 2) )
$pPlayer.falling = false;
else if($pPlayer.getLinearVelocityX() == 0 && ($pPlayer.gravity == 1 || $pPlayer.gravity == 3) )
$pPlayer.falling = false;
}
if($pPlayer.gravity!=0 && !$pPlayer.falling && gravpick=0)
{
$pPlayer.setRotation(0);
$pPlayer.falling = true;
$pPlayer.setFlip(false, false);
$pPlayer.gravity = 0;
$pPlayer.setConstantForceY(100);
$pPlayer.setConstantForceX(0);
gravpick = 1;
echo("Q.Q");
}
else if($pPlayer.gravity!=0 && !$pPlayer.falling && gravpick=0){
$pPlayer.setRotation(180);
$pPlayer.falling = true;
$pPlayer.setFlip(true, false);
$pPlayer.gravity = 2;
$pPlayer.setConstantForceY(-100);
$pPlayer.setConstantForceX(0);
gravpick = 0;
}
echo("Q2");
}
i seperated the if statement into a nested if, and it seems you cannot have 3 && conditions.
%gravpick = 0;
function Player::gravityControl() // control gravity key with the 'Q' button
{
if($pPlayer.falling)
{
if($pPlayer.getLinearVelocityY() == 0 && ($pPlayer.gravity == 0 || $pPlayer.gravity == 2) )
$pPlayer.falling = false;
else if($pPlayer.getLinearVelocityX() == 0 && ($pPlayer.gravity == 1 || $pPlayer.gravity == 3) )
$pPlayer.falling = false;
}
if($pPlayer.gravity!=0 && !$pPlayer.falling && gravpick=0)
{
$pPlayer.setRotation(0);
$pPlayer.falling = true;
$pPlayer.setFlip(false, false);
$pPlayer.gravity = 0;
$pPlayer.setConstantForceY(100);
$pPlayer.setConstantForceX(0);
gravpick = 1;
echo("Q.Q");
}
else if($pPlayer.gravity!=0 && !$pPlayer.falling && gravpick=0){
$pPlayer.setRotation(180);
$pPlayer.falling = true;
$pPlayer.setFlip(true, false);
$pPlayer.gravity = 2;
$pPlayer.setConstantForceY(-100);
$pPlayer.setConstantForceX(0);
gravpick = 0;
}
echo("Q2");
}
i seperated the if statement into a nested if, and it seems you cannot have 3 && conditions.
Associate Chris Haigler
Jester Dance
There's a few things I noticed while looking over the code:
1). The first if/else statement is missing brackets. I can't remember offhand is this causes problems or not but including the brackets would at least improve readability. The only time I leave out the brackets is when I have a simple 'if' statement (with no 'else' clauses) that executes a single line of code, i.e.
if(SomeThing == SomeThing) doSomeOtherThing();2). You reference the variable 'gravpick' a few times throughout the code but it should be '%gravpick'.
3). In addition to #2, you test to see if 'gravpick' equals 0 but forget the extra equals sign. The comparison should be if(... && %gravpick == 0) not if(... gravpick = 0).
Little syntactical problems like the above can often throw an error message which may not always be useful (depending on the code and how it's formatted, etc.).