- Home /
 
9 errors in Javascript
Hello I have a script that deals with buying a car. Here it is #pragma strict
 var NotEnoughMoney : GUIText;
 var YouBoughtTheCar : GUIText;
 
 function Start () {
     Career_Variables = GameObject.Find("career_Variables").GetComponent<Career_Variables>();
     Car_Variables = GameObject.Find("SpawningCarsPlane").GetComponent<ChooseCar1>();
 }
 
 function Update () {
 
             if (Input.GetKeyDown(KeyCode.B))
             {
                 if (Career_Variables.money >= Career_Variables.Price && carSelected == 0 && Car0Bought == false)
                     {    
                         Career_Variables.money = Career_Variables.money - 7500;
                         Car_Variables.Car0Bought = true;
                     }
                         else if (Career_Variables.money <= 7500 && carSelected == 0)
                         {
                         Car_Variables.Car0Bought - false;
                         }
             }
         
                     }
 
 
 
         function BuyCar ()
         {
             if (Career_Variables.money >= Car_Variables.Price && Car_Variables.CarSelected == 0 && !)
             {
             if (Car_Variables.CarSelected == 0)
             {
                 Career_Variables.money = Career_Variables.money - Career_Variables.Price;
                 PlayerPrefs.SetInt("Player Score", 10);
             }
             }
         }
 
               I get 9 errors such as BCE0043: Unexpected token: ). BCE0044: expecting ), found ';'. UCE0001: ';' expected. Insert a semicolon at the end. etc.
Ive been stuck on this for some time. Any help would be fantastic. Thanks in advance
Answer by AyAMrau · Sep 04, 2014 at 09:03 PM
You have some typos, errors should have line numbers, so just inspect the given line and line before for those.
On line 30 (here) you have a statement:
 if (Career_Variables.money >= Car_Variables.Price && Car_Variables.CarSelected == 0 **&& !**)
 
               There is either something missing or you have extra && ! there
On line 20:
 Car_Variables.Car0Bought **-** false;
 
               Shoul be =
Thanks for your reply. I fixed those 2 errors and that took out 3 of the 9 errors. However I still have 6 errors which I have found out are relating to lines 5&6. I used that exact same format for certain lines in other scripts and it worked perfectly with no errors. Thank you
@Dok101 I dont use Unityscript but I think that:
 .GetComponent<Career_Variables>();
 
                  is a C# only syntax for get component. You should be using:
 .GetComponent(Career_Variables);
 
                 Thanks for your reply @AyA$$anonymous$$rau . I tried that and I get 12 errors. Basically the errors are telling me that the lines 4&5 have become inactive and are not doing anything in the script.
Thank you
Hint: when asking for help, please post your full, exact code and the full, exact error messages it generates...
Thanks for your advice @tanoshimi .
I get the errors (7,9): BCE0049: Expression 'Career_Variables' cannot be assigned to.
(8,9): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(15,80): BCE0019: 'Price' is not a member of 'Career_Variables'.
(15,89): BCE0005: $$anonymous$$ identifier: 'carSelected'.
(15,109): BCE0005: $$anonymous$$ identifier: 'Car0Bought'.
(18,49): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(20,92): BCE0005: $$anonymous$$ identifier: 'carSelected'.
(22,49): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(33,55): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(33,78): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(35,29): BCE0005: $$anonymous$$ identifier: 'Car_Variables'.
(37,100): BCE0019: 'Price' is not a member of 'Career_Variables'.
These are the errors I get when change the code from .GetComponent(); to`.GetComponent(Career_Variables);`
Thank you
Your answer
 
             Follow this Question
Related Questions
Script Errors Not Sure Why 0 Answers
Animation Script Error 1 Answer
Scripting error #2! 2 Answers
problem at adding script 1 Answer