Hey, I was working on a script for firing a gun. The gun is a musket (which is why it only has 1 bullet per clip). I am a beginner at scripting and I decided to try my knowledge at scripting some things on my own. Getting the gun to shoot worked fine, but unfortunately when I tried to add reloading to the script I encountered some errors:
#pragma strict
var Bullet : GameObject;
var FirePoint : GameObject;
var Ammo = 1;
var Bullets = 15;
private var timer = 0.0;
var reloadTime = 10.0;
var Fire : String = "MusketFire";
function Start ()
{
}
function Update ()
{
if(Fire == "MusketFire")
{
if(Ammo>0)
{
if(Input.GetMouseButtonDown(0))
{
FireOneBullet();
}
}
}
if(Input.GetKey("r"))
{
Reload();
}
}
}
function FireOneBullet ()
{
var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
Ammo --;
}
function Reload ()
{
if(Ammo=0 && Bullets<0)
{
if(timer<reloadTime)
{
timer+=Time.deltaTime;
}
}else
timer=0.0;
}
if(timer>=reloadTime)
{
Ammo++ && Bullets --
}
}
It would be awesome if one of you could help me, I don’t really understand some of the errors the console is giving me because they don’t make sense from my point of view. If you do, please be sure to point out the mistakes I made so I can learn from them. Thank you in advance ![]()
Compile Error:
- FireGun.js(36,1): BCE0044: expecting EOF, found ‘}’.
Well spotted, this is the answer. To the OP : EOF usually means there is an extra parenthesis or curly brace somewhere, or one of those brackets are missing. if ( someVar == 1 ) { // all brackets are present and correct } if ( someVar == 1 )) { // extra bracket, this will error } if ( someVar == 1 ) // bracket is missing, this will error }
– AlucardJayAlso at line 53 you have an extra curly brace }else // this will error
– AlucardJayif(Ammo == 0 && Bullets <0) single equals is for assignment, double equals is for comparing
– roojerryYes awesome thank you! :) It worked! No compile errors, but my gone won't shoot at all xD Oh well, ill figure that out another time.
– Borzi