• 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 /
avatar image
Question by Chaotiche · May 18, 2014 at 09:04 PM · javascriptstring

String Problem in Java Script

Here is my script, hopefully it is easier to read now. The complete line for var sirenGameObjects : GameObject[] = GameObject.FindGameObjectsWithTag(tag

is

var sirenGameObjects : GameObject[] = GameObject.FindGameObjectsWithTag(tag.Siren);

I am getting three errors,

Assets/PlayerSightingLast.js(21,93): BCE0019: 'sirens' is not a member of 'String'.

Assets/PlayerSightingLast.js(19,58): BCE0019: 'mainLight' is not a member of 'String'.

Assets/PlayerSightingLast.js(18,62): BCE0019: 'alarm' is not a member of 'String'.

On line 21,19, and 18. Any advice?

 public var position : Vector3 = new Vector3(1000f, 1000f, 1000f);        
 public var resetPosition : Vector3 = new Vector3(1000f, 1000f, 1000f);  
 public var lightHighIntensity : float = 0.25f;                          
 public var lightLowIntensity : float = 0f;                              
 public var fadeSpeed : float = 7f;                                      
 public var musicFadeSpeed : float = 1f;                                 
 
 
 private var alarm : AlarmsLights;                                     
 private var mainLight : Light;                                          
 private var panicAudio : AudioSource;                                    
 private var sirens : AudioSource[];                                     
 
 function Awake ()
     {        
         alarm = GameObject.FindGameObjectWithTag(tag.alarm)GetComponent(AlarmsLights);
         mainLight = GameObject.FindGameObjectWithTag(tag.mainLight).light;
           panicAudio = transform.Find("secondaryMusic").audio;
           var sirenGameObjects : GameObject[] = GameObject.FindGameObjectsWithTag(tag.Siren);
         sirens = new AudioSource[sirenGameObjects.Length];
          for(var i = 0; i < sirens.Length; i++);
     {
         sirens[i] = sirenGameObjects[i].audio;
     }
 }
 
 
 function Update ()
 {
    
     SwitchAlarms();
     MusicFading();
 }
 
 
 function SwitchAlarms ()
 {
     
     alarm.alarmOn = position != resetPosition;
     
    
     var newIntensity : float;
     
     
     if(position != resetPosition)
         
         newIntensity = lightLowIntensity;
     else
         
         newIntensity = lightHighIntensity;
     
     
     mainLight.intensity = Mathf.Lerp(mainLight.intensity, newIntensity, fadeSpeed * Time.deltaTime);
     
   
     for(var i = 0; i < sirens.Length; i++)
     {
         
         if(position != resetPosition && !sirens[i].isPlaying)
             sirens[i].Play();
         
         else if(position == resetPosition)
             sirens[i].Stop();
     }
 }
 
 
 function MusicFading ()
 {
     
     if(position != resetPosition)
     {
       
         audio.volume = Mathf.Lerp(audio.volume, 0f, musicFadeSpeed * Time.deltaTime);
         
         
         panicAudio.volume = Mathf.Lerp(panicAudio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
     }
     else
     {
         
         audio.volume = Mathf.Lerp(audio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
         panicAudio.volume = Mathf.Lerp(panicAudio.volume, 0f, musicFadeSpeed * Time.deltaTime);
     }
 }
Comment

People who like this

0 Show 1
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 Chaotiche · May 18, 2014 at 07:55 PM 0
Share

the error it was giving me was this Assets/PlayerSightingLast.js(18,68): UCE0001: ';' expected. Insert a semicolon at the end. On line 18.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by KiraSensei · May 18, 2014 at 09:05 PM

Try :

 alarm = GameObject.FindGameObjectWithTag(tag.alarm).GetComponent(AlarmsLights);
Comment

People who like this

0 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 Chaotiche · May 18, 2014 at 09:14 PM 0
Share

That fixed the semicolon problem but now there are 3 new errors. Assets/PlayerSightingLast.js(21,93): BCE0019: 'sirens' is not a member of 'String'. Assets/PlayerSightingLast.js(19,58): BCE0019: 'mainLight' is not a member of 'String'. Assets/PlayerSightingLast.js(18,62): BCE0019: 'alarm' is not a member of 'String'. On line 21,19, and 18. Any advice?

avatar image KiraSensei · May 19, 2014 at 11:34 AM 0
Share

The lines you gave don't correspond with your code, except for :

 for(var i = 0; i < sirens.length; i++)

You don't want ";" at the end of this line. And no capital L for length.

Since the errors you have are very basic errors, I think you should learn some basic coding stuff before trying to actually develop your game.

avatar image Chaotiche · May 19, 2014 at 03:54 PM 0
Share

Thank you for bearing with me. I'll go do more tutorial and read more on java scripts before I continue.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Character at index of string? Finding which character is at an index like in Javascript charAt 1 Answer

get all text between two chars (js) 1 Answer

How do you display a saved name on the screen? 2 Answers

Convert Javascript class to a string 0 Answers


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