- Home /
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);
}
}
the error it was giving me was this Assets/PlayerSightingLast.js(18,68): UCE0001: ';' expected. Insert a semicolon at the end. On line 18.
Answer by KiraSensei · May 18, 2014 at 09:05 PM
Try :
alarm = GameObject.FindGameObjectWithTag(tag.alarm).GetComponent(AlarmsLights);
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?
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.
Thank you for bearing with me. I'll go do more tutorial and read more on java scripts before I continue.