- Home /
Syntax errors?
Hey all, I seems to be getting basic syntax errors on what I thought was a clean script. Seems like a curly bracket problem, but their all fine (I think?), I checked them multiple times. The earliest error is:
(62,14): BCE0044: expecting (, found 'generateFloor'.
My code:
var movementSpeed : float = .001;
var x : int = 0;
var Cube : Transform;
var Empty : Transform;
var startSize : int = 25;
var chances : int;
var generate : boolean = false;
function Start () {
//Move
transform.Translate(Vector3.left * movementSpeed, Space.World);
}
//********************************
//Raycast
//********************************
function Update () {
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, up * 10, Color.green);
if (Physics.Raycast (transform.position, up, hit)) {
generate = true;
}
//********************************
//Generate chances
//********************************
chances = Random.Range (1,101);
if (generate == true) {
if (chances <= 100) {
generateFloor();
}
if (chances <= 0) {
generateDrop();
}
if (chances <= 0) {
generatePlatform();
}
}
//********************************
//Generate level
//********************************
function generateFloor () {
Instantiate (Cube, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
generate = false;
}
function generatePlatform() {
Instantiate (Cube, transform.position + Vector3(startSize, 1, 0), Quaternion.identity);
generate = false;
}
function generateDrop() {
Instantiate (Empty, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
generate = false;
}
//*********************************//
function OnBecameInvisible () {
Destroy(gameObject);
}
}
Please, please, please ask for details if you need them and if this big block of code is to intimidating for a more casual forum, I will delete the question gladly. Thanks.
Answer by clunk47 · Sep 05, 2013 at 02:16 AM
A couple braces '}' are missing. I usually format my code like the following so these are easier to spot. I also would use a new variable for instantiations, so they act like a "Clone" of your prefab, to avoid data loss if the objects are destroyed.
#pragma strict
var movementSpeed : float = .001;
var x : int = 0;
var Cube : Transform;
var Empty : Transform;
var startSize : int = 25;
var chances : int;
var generate : boolean = false;
function Start ()
{
//Move
transform.Translate(Vector3.left * movementSpeed, Space.World);
}
//********************************
//Raycast
//********************************
function Update ()
{
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, up * 10, Color.green);
if (Physics.Raycast (transform.position, up, hit))
{
generate = true;
}
//********************************
//Generate chances
//********************************
chances = Random.Range (1,101);
if (generate == true)
{
if (chances <= 100)
{
generateFloor();
}
if (chances <= 0)
{
generateDrop();
}
if (chances <= 0)
{
generatePlatform();
}
}
}
//********************************
//Generate level
//********************************
function generateFloor ()
{
var newCube = Instantiate (Cube, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
generate = false;
}
function generatePlatform()
{
var newCube = Instantiate (Cube, transform.position + Vector3(startSize, 1, 0), Quaternion.identity);
generate = false;
}
function generateDrop()
{
var newCube = Instantiate (Empty, transform.position + Vector3(startSize, 0, 0), Quaternion.identity);
generate = false;
}
//*********************************//
function OnBecameInvisible ()
{
Destroy(gameObject);
}
Answer by weenchehawk · Sep 05, 2013 at 01:56 AM
Seems to me like your update() function is missing a closing curly brace }.
your indentation (as it shows above) seems to confuse line 40's opening brace and the closing braces on line 53 & 54
The brace on line 53 belongs to the if on line 50,
The brace on line 54 belongs to the if on line 40
leaving no closing brace.
Seems correct. Be careful indenting your code and you should never have this problem. Count yourself lucky that this time actually gave you a compile error.
I'll keep that in $$anonymous$$d. Cluck47 got the answer first though, but thank's alot for the answer!
Your answer
Follow this Question
Related Questions
Script error with turrets 5 Answers
Simple syntax error that I can't seem to find 2 Answers
Javascript syntax errors with basic expressions 2 Answers
Mouse look script help 1 Answer
Help solving for loop error 1 Answer