Im making a game like minecraft and it throws an error that i know isnt one… code below… error marked with an arrow… PLS HELP
Error :
Assets/scripts/BlockMaker.js(22,27): BCE0043: Unexpected token: -=.
Code (Its long):
#pragma strict
var GrassBlock : Transform;
var StoneBlock : Transform;
var BlockSeleted : float = 1;
var Range : float = 20;
function Start () {
}
function Update ()
{
var BlockSeleted : float = 1;
var Range : float = 20;
if (Input.GetKeyDown(KeyCode.Q))
{
var BlockSelected -= 1; <------- HERES THE ERROR
}
if (Input.GetKeyDown(KeyCode.E))
{
var BlockSelected += 1;
}
if(Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
{
var Hit : RaycastHit;
var LookingDirection = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, LookingDirection, Hit, 20))
{
if (Input.GetMouseButtonDown(1))
{
if(var BlockSelected ==1)
{
var GrassBlock : Transform = Instantiate (GrassBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
GrassBlock.tag = "GrassBlock";
}
if(var BlockSelected ==2)
{
var StoneBlock : Transform = Instantiate (StoneBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
GrassBlock.tag = "StoneBlock";
}
}
}
else
{
Destroy(Hit.transform.gameObject);
}
}
}
Stephen7755:
Im making a game like minecraft and it throws an error that i know isnt one… code below… error marked with an arrow… PLS HELP
Error :
Assets/scripts/BlockMaker.js(22,27): BCE0043: Unexpected token: -=.
Code (Its long):
#pragma strict
var GrassBlock : Transform;
var StoneBlock : Transform;
var BlockSeleted : float = 1;
var Range : float = 20;
function Start () {
}
function Update ()
{
var BlockSeleted : float = 1;
var Range : float = 20;
if (Input.GetKeyDown(KeyCode.Q))
{
var BlockSelected -= 1; <------- HERES THE ERROR
}
if (Input.GetKeyDown(KeyCode.E))
{
var BlockSelected += 1;
}
if(Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
{
var Hit : RaycastHit;
var LookingDirection = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, LookingDirection, Hit, 20))
{
if (Input.GetMouseButtonDown(1))
{
if(var BlockSelected ==1)
{
var GrassBlock : Transform = Instantiate (GrassBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
GrassBlock.tag = "GrassBlock";
}
if(var BlockSelected ==2)
{
var StoneBlock : Transform = Instantiate (StoneBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
GrassBlock.tag = "StoneBlock";
}
}
}
else
{
Destroy(Hit.transform.gameObject);
}
}
}
It is expecting an initialisation i guess, due to the keyword ‘var’. Try to remove it.
Same happens few more times in your code.
It’s totally an error. You can’t use -= or += when declaring variables, and in fact you don’t want to declare variables there at all. Some additional things: I seriously doubt you want to use floats for that, and it’s easier to read the code if you stick with the convention of using lowercase for variable names; uppercase is for classes and functions.
–Eric
Dameon
April 29, 2014, 10:18pm
4
You misspelled BlockSelected as BlockSeleted on line 6.
I caught that when fixing it… thanks tho!
Eric5h5:
It’s totally an error. You can’t use -= or += when declaring variables, and in fact you don’t want to declare variables there at all. Some additional things: I seriously doubt you want to use floats for that, and it’s easier to read the code if you stick with the convention of using lowercase for variable names; uppercase is for classes and functions.
–Eric
I had them declared at the top, but when i removed var, it fixed it… i made all my variables lowercase too … thanks!