For loop / incrementing values causes BCE0034

Hi all,

I’ve been learning about FOR loops today as well as well as starting to re-write my code structure generally. Mainly as my understanding has grown somewhat to take into consideration the different object states. As I’ve never worked with OO languages before.

Anyway here are my two scripts. One of which has a mini loop to set a trigger back to false after 5 update() ticks.

I have three BCE0034 errors
Assets/robo_istat.js(22,10): BCE0034: Expressions in statements must only be executed for their side-effects. // Which is the line reading - for (i < 5; i++;)
Assets/robo_istat.js(20,36): BCE0034: Expressions in statements must only be executed for their side-effects. // Which is the line reading - { chMotor.movement.maxForwardSpeed + 500;
Assets/robo_powerup.js(20,15): BCE0034: Expressions in statements must only be executed for their side-effects. // Which is the line reading - stat_increase + 500;

robo_istat.js


#pragma strict
var powerup : robo_powerup;
var Start_Player_Agility = 10; // not used yet
var Start_Player_Weight = 100; //value that takes away speed
var Start_Player_Speed = 200; //forward speed only control (not using strafe/back)
var Start_Jump_Speed = 2; //a variable that we use to adjust forward speed when jumping
var chMotor : CharacterMotor; //Default CharacterMotor script used for control referencing
var player: Transform;
var unequippedpostspeed = Start_Player_Speed - Start_Player_Weight; //Unequipped calculated speed excluding bonus's
var i = 0;
function Start () {

chMotor = GetComponent(CharacterMotor);
powerup = GetComponent(robo_powerup);
}
function Update () {

if (powerup.triggered == true)
{ chMotor.movement.maxForwardSpeed + 500;
 print(powerup.numberofpus);         //quote number of power ups
  for (i < 5; i++;)
{ powerup.triggered = false;
}
}
if (powerup.triggered != true)
{ chMotor.movement.maxForwardSpeed = unequippedpostspeed;
 print ("Normal speed");
}
}

Followed by robo_powerup


#pragma strict
var destroyedpowerup : GameObject; // Declare the object to be destroyed
var target : Collider; //this is the variable that will hold the colliding object
static var triggered : boolean = false; //If we only want to detect the first time it's triggered
static var numberofpus : int; // ready for number of powerups to be totalled
static var stat_increase : int;

function Start () {
}

function OnTriggerEnter(collision : Collider)
{
if (collision != target) //The colliding object isn't our object
{
return; //don't do anything if it's not our target
}
triggered = true;
numberofpus++;
print("Increasing speed by... 500");
stat_increase + 500;
Destroy(destroyedpowerup);

}
 
// Print - to debug testing
// Destroy sphere

Thank you for the help :slight_smile:

The problem is in the exact syntax of the ‘for’ statement.

How it should be is this:

for (starting conditions; end condition; loop operation) {
    stuff
}

However, because you haven’t set a starting condition, you are confusing it by giving it inappropriate commands in each position. Try something that looks like this:

for (i = 0; i < 5; i++)
{
    powerup.triggered = false;
}