Search Unity

Nothing working in script! (JavaScript)

Discussion in 'Scripting' started by Fireking883, Dec 22, 2014.

  1. Fireking883

    Fireking883

    Joined:
    Nov 28, 2014
    Posts:
    50
    Code (JavaScript):
    1. #pragma strict
    2. // Variables
    3. var Bal : int = 0;
    4. var CostOfStarter : int = 0;
    5. var StarterObject1 : GameObject;
    6. var StarterObject2 : GameObject;
    7. var StarterObject3 : GameObject;
    8. var ScienceBall1 : GameObject;
    9. var ScienceBall1Add : int = 25;
    10. var StarterButton : GameObject;
    11. var ScienceBall2Teir1 : GameObject;
    12. var CostOfDouble1 : int = 300;
    13. var ButtonDouble1 : GameObject;
    14. var ClickerAmount : int = 1;
    15. var Plank1 : GameObject;
    16. var Plank2 : GameObject;
    17. var Plank3 : GameObject;
    18. var Tester : GameObject;
    19. var TesterUpgrade : GameObject;
    20. var UpgradedClicker1 : GameObject;
    21. var ClickerButton1 : GameObject;
    22.  
    23. // Make every purchasable game object disabled
    24. function Start(){
    25.         StarterObject1.SetActive(false);
    26.         StarterObject2.SetActive(false);
    27.         StarterObject3.SetActive(false);
    28.         ScienceBall1.SetActive(false);
    29.         ScienceBall2Teir1.SetActive(false);
    30.         ButtonDouble1.SetActive(false);
    31.         Plank1.SetActive(false);
    32.         Plank2.SetActive(false);
    33.         Plank3.SetActive(false);
    34.         Tester.SetActive(false);
    35.         UpgradedClicker1.SetActive(false);
    36.         TesterUpgrade.SetActive(true);
    37.         ClickerButton1.SetActive(true);
    38.  
    39.      
    40. }
    41. function Update(){
    42.     if (Bal > 0)
    43. }
    44. function Clicker() {
    45.     Bal += ClickerAmount;
    46.     audio.Play();
    47. }
    48. // Only for starter tech
    49. function PurchaseStarter() {
    50.     Debug.Log("PurchaseStarter function works");
    51.     if (CostOfStarter <= Bal)
    52.         {
    53.         BuyStarter();
    54.         }
    55. }
    56. // Spawn in everything for StarterTech
    57. function BuyStarter() {
    58.     StarterObject1.SetActive(true);
    59.     StarterObject2.SetActive(true);
    60.     StarterObject3.SetActive(true);
    61.     ScienceBall1.SetActive(true);
    62.     StarterButton.SetActive(false);
    63.     ButtonDouble1.SetActive(true);
    64. }
    65.  
    66. function AddTeir1(Add: int) {
    67.     Bal += ScienceBall1Add;
    68.     Debug.Log("Phase 3 works");
    69. }
    70. // Display score
    71. function OnGUI () {
    72.         GUI.Label (Rect (10, 10, 100, 20), "Science: "+ Bal);
    73.     }
    74. //Only for DoubleSpeed
    75. function PurchaseDouble1(){  
    76.     Debug.Log("PurchaseDouble1 Works");
    77.     if (CostOfDouble1 <= Bal)
    78.         {
    79.         BuyDouble1();
    80.         Bal -= CostOfDouble1;
    81.         }
    82. }
    83. // Spawn in everything for Double1 button
    84. function BuyDouble1(){
    85.         ScienceBall2Teir1.SetActive(true);
    86.         ButtonDouble1.SetActive(false);
    87.         Plank1.SetActive(true);
    88.         Plank2.SetActive(true);
    89.         Plank3.SetActive(true);
    90.  
    91. }
    92. // Upgrade Clicker1 to Clicker2 (X2 amount needs to be added)
    93. function UpgradeClicker(){
    94.     TesterUpgrade.SetActive(false);
    95.     ClickerButton1.SetActive(false);
    96.     UpgradedClicker1.SetActive(true);
    97.     ClickerAmount += 1;
    98.     Bal -= 600;
    99.  
    100. }
    OK so I was making a small tycoon type game in unity and I put together this JS and it worked perfectly for a long time. Now I know there are more efficient ways of doing this but I did not come here for that. I was making a menu scene and I had just backed up all my scripts. I accidentally deleted the script folder, so I put the back in. When I did this, the errors showed up, so I deleted scripts until I figured out it was this one causing the problem. Now, I am a beginner to unity an JS in general so I may be overlooking something obvious, and I'm sorry if I am.


    Here are the errors:
    Assets/Bal.js(43,1): BCE0043: Unexpected token: }.
    Assets/Bal.js(44,10): BCE0044: expecting (, found 'Clicker'.
    Assets/Bal.js(44,19): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(49,10): BCE0044: expecting (, found 'PurchaseStarter'.
    Assets/Bal.js(57,10): BCE0044: expecting (, found 'BuyStarter'.
    Assets/Bal.js(57,22): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(66,10): BCE0044: expecting (, found 'AddTeir1'.
    Assets/Bal.js(66,19): BCE0043: Unexpected token: Add.
    Assets/Bal.js(66,28): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(71,10): BCE0044: expecting (, found 'OnGUI'.
    Assets/Bal.js(71,18): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(75,10): BCE0044: expecting (, found 'PurchaseDouble1'.
    Assets/Bal.js(75,27): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(84,10): BCE0044: expecting (, found 'BuyDouble1'.
    Assets/Bal.js(84,22): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(93,10): BCE0044: expecting (, found 'UpgradeClicker'.
    Assets/Bal.js(93,26): UCE0001: ';' expected. Insert a semicolon at the end.
    Assets/Bal.js(101,1): BCE0044: expecting }, found ''.



    Thanks in advance for answers! Oh and here is the code for download if you want a closer look:
     

    Attached Files:

    • Bal.js
      File size:
      2.3 KB
      Views:
      721
    Last edited: Dec 22, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. Fireking883

    Fireking883

    Joined:
    Nov 28, 2014
    Posts:
    50
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Line 42 is an if statement that doesn't do anything.
     
  5. Fireking883

    Fireking883

    Joined:
    Nov 28, 2014
    Posts:
    50
    Well... that fixes some things... and so does deleting that whole Update function :D! It works! Thanks so much!