Script error

Hi all! I have a few errors in this script, but I looked on the internet and tried several solutions but I still don’t understand the errors.

static var bobbingSpeed;
static var bobbingAmount;
static var playerStamina = 600;

static var audioStepLength: float = 0.5;
static var stepSound = 0;

var walkSpeed: float = 7; // regular speed
var sneakSpeed: float = 3; // sneaking speed
var runSpeed: float = 20; // running speed

var walkStep: float = 0.5;
var sneakStep: float = 1;
var runStep: float = 0.45;

private var isRunning: boolean = false;

private var chMotor: CharacterMotor;
private var tr: Transform;
private var dist: float; // distance to ground

function Start(){
    chMotor = GetComponent(CharacterMotor);
    tr = transform;
    var ch:CharacterController = GetComponent(CharacterController);
    dist = ch.height/2; // calculate distance to ground
}

function Update(){
    if(chMotor.grounded){
        bobbingSpeed = 0.20;
        bobbingAmount = 0.3;
    } else {
        bobbingSpeed = 0;
        bobbingAmount = 0;
    }
    
    var vScale = 1.0;
    var speed = walkSpeed;
    audioStepLength = walkStep;
    stepSound = 2;
 
 if (!isRunning){
 if (playerStamina < 250){
   playerStamina = playerStamina+2;
 }
 } else if (isRunning){
 if (playerStamina >= 0){
   playerStamina = playerStamina-3;
 }
 }
 
 isRunning = false;
 
    if (Input.GetKey("left shift") && chMotor.grounded){ // press LShift to run
 if (playerStamina >= 3){
   isRunning = true;
   
   audioStepLength = runStep;
   stepSound = 0;
   
   speed = runSpeed;
      bobbingSpeed = 0.30;
      bobbingAmount = 0.3;
     } else {
   isRunning = false;
     }
    }
 
    if (Input.GetKey("c")){ // press C to sneak
        speed = sneakSpeed;
        bobbingSpeed = 0.15;
        bobbingAmount = 0.1;
        
        audioStepLength = sneakStep;
        stepSound = 1;
    }
    
    chMotor.movement.maxForwardSpeed = speed; // set max speed
    var ultScale = tr.localScale.y; // crouch/stand up smoothly 
    tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
    tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
}

function Update(){
    if(isRunning == true){
       {
         SetFOV(70.0)
       }
    }
 
function Update(){
    if(isRunning == false){
       {
         SetFOV(60.0);
       }
    }
}
}

These errors remain: 88,22 ; Expected. Insert semicolon. 92,10 expecting ( found Update. 92,18 ; Expected. Insert semicolon.
Can anyone please give advice or anything thanks!

Hmm, it’s a bit difficult to locate the error because I can’t tell where lines 88 and 92 are…, but those errors usually mean that you have either done the following:

  • Forgotten to insert a “;” at the
    end of a command line. Or you have put one where it shouldn’t be…

  • Forgotten to place enough “(” or
    “)” for your conditions/arguments
    or maybe placed additional ones by
    accident.

  • Also watch out for “{” and “}” as
    they can confuse the compiler too
    if they are missing…

It should be an easy fix, I get these errors all the time when I’m getting tired and being clumsy.

You will usually find them above or below the lines it actually reports the error on as it continues to compile your code until it reached a point where it stops making sense. So you’ll have to do some hunting. But as of right now, I can take a quick guess that it may be your update Loops at the end there. You have two update Loops…you should remove one and put the code inside the first update loop…I’m expecting it to look more like this…assuming that SetFOV is a function that you are passing float parameters too…

function Update(){
	if(isRunning){
		SetFOV(70.0);
	}else{
		SetFOV(60.0);
    }
}

I see you have another Update loop further up in your script too. You should have just one update loop. You need put everything in it which needs updating every frame.