Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Gigioparanormal · Aug 28, 2015 at 07:53 PM · javascriptflashlightscripterrorpick-up

Script error to pick-up flashlight

Hi, sorry for my english but I'm italian. Ehm i created a script for pick-up a flashlight but there is 3 errors (some words are italian but you can understand)

(there are 2 errors of) Assets/Torcia.js(55,16): BCE0044: expecting }, found 'else'. (and 1 of) Assets/Torcia.js(65,10): BCE0044: expecting EOF, found '}'.

what i can do?

This is the script

 var raccolta : boolean;
  var posizioneT : Transform;
  var maxDist : float;
  var maxAngolo : float;
  var mainCamera : Transform;
  var accesa : boolean;
  var luce : Light;
  var moltiplucatore : float;
 
  function update ()
  {
  if(!raccolta) 
 {
  GetComponent(Collider).enabled = true;
  rigidbody.useGravity = true;
  rigidbody.iaKinematic = false;
  transform.parent = null;
 
  if(Input.GetButtonDown("Fire1") && Vector3.Distance(transform.position, mainCamera.position) < maxDist && Vector3.Angle(transform.position - mainCamera.position, mainCamera.forward) < maxAngolo);
  {
  raccolta = true;
  }
  else
  {
  GetComponent(Collider) = false;
  rigidbody.useGravity = false;
  rigidbody.iaKinematic = true;
  transform.parent = mainCamera;
  transform.position = posizioneT.position;
  trasform.rotation = posizioneT.rotation;
 
  if(accesa)
  {
  luce.intensity -= Time.deltaTIme * 0.1 * moltiplicatore;
  luce.enabled = true;
  if(Input.GetButtonDown("Fire2")) accesa = false;
  if(Input.GetButton("Fire3"))
  {
  luce.range = 15;
  luce.spotAngle = 12;
  }
  else
  {
  luce.range = 10;
  luce.spotAngle = 30;
  }
  else
  {
  luce.enabled = false;
  if(Input.GetButtonDown("Fire2")) accesa = true;
  }
  }
  }
  }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hexagonius · Aug 28, 2015 at 08:12 PM

both errors tell you which lines they appear (10 and 16). if you look at 10, update needs to be uppercase U, on 16, it's isKinematic, not iaKinematic. If using Monodevelop a doubleclick on an error within unity should take you exactly there

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Landern · Aug 28, 2015 at 08:17 PM 0
Share

And if it is all of it in the original post, you're missing a closing curly brace on the last line to close the Update function block

avatar image ransomink · Aug 29, 2015 at 01:22 AM 0
Share

Actually the errors are on line 55, column 16; and line 65, column 10. They refer to not having closing brackets '}' but ins$$anonymous$$d have an 'else' statement. But a strange coincidence that there are errors on lines 10 and 16!

avatar image
1

Answer by ransomink · Sep 06, 2015 at 09:51 PM

I went ahead and recreated the script for turning the flashlight on/off. I simplified draining the battery and charging the battery by placing them inside of functions. It is much easier than having long if statements inside of Update(). I moved the flicker code within a function as well, so if you ever need to access these again, you can simply call the function name.

Everything important is commented (well, I hope) and the Debug.Log() are there for testing purposes; you can delete or comment those out.

In the start function—at the bottom of the script—I gave you two options for referencing the flashlight. The comments explain their use but both of them are being executed, so choose which one you wish to use and comment out the other.

I've tested it myself and it works wonders. Please let me know if any problems persist. I hope this helps!

Character limit exceeded, so I'll post a pastebin file: Flashlight

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ransomink · Sep 13, 2015 at 06:05 PM 0
Share

@Gigioparanormal: Were you able to test or check out the flashlight script?

avatar image
0

Answer by ransomink · Aug 29, 2015 at 01:17 AM

Your code is quite confusing and not as readable. This problem stems from its format/layout. You should definitely indent your curly brackets to better understand what piece of code lies in each scope of the project.

Line 10: Needs to be Update (capital "U")

 function update ()

Line 16 Needs to be rigidbody.isKinematic

 rigidbody.iaKinematic = false;

Line 25: Needs to be GetComponent(Collider).enabled = false;

 GetComponent(Collider) = false;

Line 27: Needs to be rigidbody.isKinematic

 rigidbody.iaKinematic = true;

Line 30: Needs to be transform.rotation

 trasform.rotation = posizioneT.rotation;

These were the ones I could find; hopefully there isn't more. This next part is difficult because I can't tell if some of the if statements are within the same scope or on their own (if they're inside of another if statement or by itself.

The if statement @ Line 37 has 2 else statements which is not possible. It can be:

 // first option
 if ( option1 )
 {
     // do something
 }
 // second option
 else if ( option2 )
 {
     // do something
 }
 // neither option
 else
 {
     // do something
 }

or:

 // first option
 if ( option1 )
 {
     // do something
 }
 // second option
 else ( option2 )
 {
     // do something
 }

NOTE: You should really indent for class, function, enum, if, for, etc.

The if statement on line 19 encapsulates the rest of the script. Is this suppose to happen or should there be a closing bracket on line 31?

 // line 19 below
 if(Input.GetButtonDown("Fire1") && Vector3.Distance(transform.position, mainCamera.position) < maxDist && Vector3.Angle(transform.position - mainCamera.position, mainCamera.forward) < maxAngolo);
 {
 raccolta = true;
 }
 else
 {
 GetComponent(Collider) = false;
 rigidbody.useGravity = false;
 rigidbody.iaKinematic = true;
 transform.parent = mainCamera;
 transform.position = posizioneT.position;
 trasform.rotation = posizioneT.rotation;
 // line 31

I attempted to format your code, but as I previously stated, I don't know where your closing brackets should be, so it may be incorrect. After looking at the new format, you can easily fix the misplaced brackets.

After looking more at the code, the if statements look out-of-order. You have 2 if statements with the same condition setting the same variable to different values. I'm not sure what it suppose to happen, but here is the formatting at least...

 var raccolta        : boolean;
 var posizioneT      : Transform;
 var maxDist         : float;
 var maxAngolo       : float;
 var mainCamera      : Transform;
 var accesa          : boolean;
 var luce            : Light;
 var moltiplucatore  : float;
 
 function Update ()
 {
     if (!raccolta) 
     {
         GetComponent(Collider).enabled = true;
         rigidbody.useGravity           = true;
         rigidbody.isKinematic          = false;
         transform.parent               = null;
         
         if (Input.GetButtonDown("Fire1") && Vector3.Distance(transform.position, mainCamera.position) < maxDist && Vector3.Angle(transform.position - mainCamera.position, mainCamera.forward) < maxAngolo);
         {
             raccolta = true;
         }
         else
         {
             GetComponent(Collider) = false;
             rigidbody.useGravity   = false;
             rigidbody.isKinematic  = true;
             transform.parent       = mainCamera;
             transform.position     = posizioneT.position;
             transform.rotation     = posizioneT.rotation;
         }
         
         if (accesa)
         {
             luce.intensity -= Time.deltaTIme * 0.1 * moltiplicatore;
             luce.enabled    = true;
         }
         
         if (Input.GetButtonDown("Fire2")) accesa = false;
         
         if (Input.GetButton("Fire3"))
         {
             luce.range     = 15;
             luce.spotAngle = 12;
         }
         else
         {
             luce.range     = 10;
             luce.spotAngle = 30;
         }
             
         luce.enabled = false;
         
         if (Input.GetButtonDown("Fire2")) accesa = true;
     }
 }

Hope this helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Gigioparanormal · Aug 29, 2015 at 11:11 AM

Sorry, I tried to solve the errors and write your script, in your script there are only one error

Assets/Pick-up flashlight.js(6,32): BCE0044: expecting ''', found '\r'.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ransomink · Aug 29, 2015 at 08:09 PM 0
Share

You should change your answer to a comment under my answer, so every time you respond it isn't as a new answer. (Will be confusing for other looking to help or find the same solution.)

I just looked at the code I put up and line 6 is: var accesa : boolean; . There is no '\r' on that line. Can you put up the new code you are working with and we can go from there...

avatar image Gigioparanormal · Aug 31, 2015 at 08:24 PM 0
Share

Sorry, I'm not good in Javascript, i created an another script but there are not an error, but is similar when i press F or another key, i can't turn on the light, why? There is another script

var linkedLight : Light; var switchon: AudioClip; var switchoff: AudioClip;
var is_on: boolean = false;

var maxPower : float = 100;
private var currentPower : float;
var speed : float = 5.0;
private var alpha : float;
private var duration : float = 0.2;
private var baseIntensity : float;

function Start(){
currentPower=maxPower; baseIntensity=linkedLight.GetComponent.().intensity; }

function Update () {

 if(Input.GetButtonUp("Flash")){
     if (is_on)             
     {
         flash_off();         
         is_on=false;      
     }
     else                   
     {
         flash_on();            
         is_on=true;          

linkedLight.GetComponent.().intensity = baseIntensity; }
}

if(currentPower < maxPower/4 && linkedLight.enabled){ var phi : float = Time.time / duration 2 $$anonymous$$athf.PI; var amplitude : float = $$anonymous$$athf.Cos( phi ) * .5 + baseIntensity; linkedLight.GetComponent.().intensity = amplitude + Random.Range(0.1, 1.0) ; } linkedLight.GetComponent.().color = Color(alpha/maxPower, alpha/maxPower, alpha/maxPower, alpha/maxPower); alpha = currentPower;

     if (is_on==true) {  
         if(currentPower > 0.0) currentPower -= Time.deltaTime * speed; 
         if(currentPower <= 0.0) {flash_off(); is_on=false;} 
     }
     if (is_on==false) {    
     if(currentPower < maxPower) currentPower += Time.deltaTime * speed/2; 
 }

} function flash_on (){
Camera.main.GetComponent.().PlayOneShot(switchon);
linkedLight.enabled =true;
}

function flash_off(){ Camera.main.GetComponent.().PlayOneShot(switchoff);
linkedLight.enabled =false;
}

//If you want to display percentage of charge just uncomment all lines which under function OnGUI () { GUI.Label (Rect(70, Screen.height - 75,150,60), "Battery: " + currentPower.ToString("F0") + "%"); }

avatar image binaryspace1010 · Aug 31, 2015 at 08:40 PM 0
Share

@Gigioparanormal Hey there, I'm currently working out your problem! I'll let you know when I'm done! :)

avatar image
0

Answer by binaryspace1010 · Aug 31, 2015 at 09:21 PM

@Gigioparanormal It's not Perfect, but i have made a piece of code that works! Here it is:

'#pragma strict

var flashLight : Light;

var switchon: AudioClip;

var switchoff: AudioClip;

var is_on: boolean = false;

var maxPower : float = 100;

var currentPower : float;

var speed : float = 5.0;

private var baseIntensity : float;

function Start() {

currentPower = maxPower;

flashLight = GameObject.Find("Point light").GetComponent.();

baseIntensity = flashLight.intensity; }

function Update () {

if(Input.GetKey("f")) // If the "F" key is pressed {

if (is_on == false) { FlashOn(); }

else if(is_on == true) { FlashOff(); } }

 if (is_on == true) 
 {  
     if(currentPower > 0.0) 
             {
                     currentPower -= Time.deltaTime * speed; 
             }

             if(currentPower <= 0.0) 
     {
         FlashOff(); 
         is_on = false;
     } 
 }
 
 if (is_on == false) 
 {    
     if(currentPower < maxPower) currentPower += Time.deltaTime * speed/2; 
 }
 
 if(currentPower < maxPower / 4 && is_on == true)
 {
     //Flicker Light
     
 }

}

function FlashOn () { flashLight.enabled = true; is_on = true; }

function FlashOff() { flashLight.enabled = false; is_on = false; }'

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gigioparanormal · Sep 05, 2015 at 01:12 PM 0
Share

There are just four errors, and there is the errors

Assets/Scripts/Pick up a flashlight.js(59,1): BCE0044: expecting EOF, found '}'. Assets/Scripts/Pick up a flashlight.js(23,58): BCE0043: Unexpected token: (. Assets/Scripts/Pick up a flashlight.js(23,58): UCE0001: ';' expected. Insert a semicolon at the end. Assets/Scripts/Pick up a flashlight.js(23,57): BCE0043: Unexpected token: ..

avatar image ransomink · Sep 06, 2015 at 07:25 PM 0
Share

I don't know where line 59 is or the other line errors because half the code is outside the code block. I'll go ahead and try to create a new script for turning on/off the flashlight myself...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a working flashlight with batteries? 0 Answers

Error : Unknown identifier : FlashLight 1 Answer

enemy patrolling using javascript??? 0 Answers

First Person Controller error, "IndexOutOfRangeException:Array index is out of range." 1 Answer

How to use an implicit generic list as a parameter? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges