- Home /
Errors in Scripting
I am sorry that I keep having to post new questions. I am new, but I think I have finaly figured out how to use the 10101 button correctly now. Haha. So I have multiple errors in my script. I try to resolve them by following the directions on the alerts, but it just creates new ones. I am down to several last errors.
BCE0044: expecting (, found 'OnControllerHit'
BCE0044: expecting ), found ':'
UCE0001: ';' expected. Insert a semicolon at the end
BCE0043: Unexpected token: )
BCE0043: Unexpected token: if
UCE0001: ';' expected. Insert a semicolon at the end
BCE0044: expecting :, found '='
Here is my script....
//Moving Around
var speed = 3.0;
var rotateSpeed = 3.0;
//Shooting
var bullitPrefab:Transform;
//Dying
private var dead = false;
//Getting Hit
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate()
{
if(dead)
if(gotHit)
{
if(tumbleSpeed < 1)
{
//we're not hit anymore... reset and get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else
{
//we're hit! Spin our character around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
function OnControllerHit (hit : ControllerColliderHit) //onTriggerEnter : collider
{
if(hit.gameObject.tag == "fallout")
{
dead = true; //the error is on this line, please help!
//subtract life here
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enemyProjectile")
{
gotHit = true;
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPointGood").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
{
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
}
@script RequireComponent(CharacterController)
Answer by Dreamblur · Jul 02, 2011 at 07:15 PM
Your LateUpdate method isn't closed. The method is OnControllerColliderHit, not OnControllerHit. You have that if(dead) line floating there doing nothing. The last block of code does not belong to any scope.
Answer by oliver-jones · Jul 02, 2011 at 07:16 PM
Okay doky, you had a few } in the wrong place, and also - I think you were missing an else statement towards the end. But here it is - with no errors:
var speed = 3.0;
var rotateSpeed = 3.0;
//Shooting
var bullitPrefab:Transform;
//Dying
private var dead = false;
//Getting Hit
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate(){
if(dead){
if(gotHit){
if(tumbleSpeed < 1){
//we're not hit anymore... reset and get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else{
//we're hit! Spin our character around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
}
}
function OnControllerHit (hit : ControllerColliderHit){
if(hit.gameObject.tag == "fallout"){
dead = true; //the error is on this line, please help!
//subtract life here
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enemyProjectile"){
gotHit = true;
}
}
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump")){
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPointGood").transform.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
else{
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
}
@script RequireComponent(CharacterController)
This removed my errors, but now when I try to enter play mode, my character is stuck in midair.
Answer by GuyTidhar · Jul 02, 2011 at 07:24 PM
var speed = 3.0;
var rotateSpeed = 3.0;
//Shooting
var bullitPrefab:Transform;
//Dying
private var dead = false;
//Getting Hit
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate()
{
if(dead)
if(gotHit)
{
if(tumbleSpeed < 1)
{
//we're not hit anymore... reset and get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else
{
//we're hit! Spin our character around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
}
function OnControllerHit (hit : ControllerColliderHit) //onTriggerEnter : collider
{
if(hit.gameObject.tag == "fallout")
{
dead = true; //the error is on this line, please help!
//subtract life here
HealthControl.LIVES -= 1;
// Is LIVES a static variable of HealthControl? If not, this will not compile
}
if(hit.gameObject.tag == "enemyProjectile")
{
gotHit = true;
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPointGood").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
// What was the purpose of these {}?
/*
}
{
{
*/
// I removed them, but I do not know what was the reason they were here for...
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
}
@script RequireComponent(CharacterController)
Answer by aldonaletto · Jul 02, 2011 at 07:54 PM
It seems you've mixed parts of several scripts in one single code, but in the wrong places! It looks like a Frankenstein with a leg and one arm replaced by the Tornado Twins heads! There were several answers here, but nobody (me included) seems to know how to solve the puzzle.
Well, let's try to bring some order to the chaos: that lost if (dead) at the beginning seems to be part of the equally lost lines at the end - they seem to form a re-spawn code intended to bring the character back to life. Supposing it's true, the whole script is:
//Moving Around
var speed = 3.0;
var rotateSpeed = 3.0;
//Shooting
var bullitPrefab:Transform;
//Dying
private var dead = false;
//Getting Hit
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate()
{
if(gotHit)
{
if(tumbleSpeed < 1)
{
//we're not hit anymore... reset and get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else {
//we're hit! Spin our character around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
}
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if (hit.gameObject.tag == "fallout"){
dead = true;
//subtract life here
HealthControl.LIVES -= 1;
}
if (hit.gameObject.tag == "enemyProjectile"){
gotHit = true;
}
}
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed * Time.deltaTime);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPointGood").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
if (dead)
{
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
}
@script RequireComponent(CharacterController)
I really don't know if this script will do something - you will need other pieces, like a collider tagged fallout, another script called HealthControl.js with an int variable LIVES in there, a bullet prefab tagged enemyProjectile and God-knows-what more, but good luck anyway!
I have the other pieces, including tags and scripts. Haha. I am actually trying to alter some of the script from a Tornado Twins tutorial. The only thing that I am really changing is the characters. In their tutorial, they made a game with a worm vs turrets. I am am doing a robot vs robot turrets.
The changes you made to the script worked the best out of all so far. The only issue now is when I enter play mode, my character spawns as usual in the correct place. But, from there, all I can make him do is rotate. $$anonymous$$y character will not move back or forward anymore...
Your answer
Follow this Question
Related Questions
script not working 2 Answers
Script error. Please Help! 4 Answers
BCE0044: expecting (, found 'OnTriggerEnter'. 1 Answer
Assets/NewBehaviourScript.js(10,29): BCE0044: expecting :, found ';'. HELP! 2 Answers