Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

function Start problem

Discussion in 'Scripting' started by cruising, Jun 30, 2014.

  1. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    I getting this error BCE0044: expecting EOF, found 'else'. But it seams i cant get it to work what ever i do with the curly brace's.

    CODE:
    Code (JavaScript):
    1. function Start() {
    2.     fpsarray = new int[Screen.width];
    3.     Time.timeScale = 1.0;
    4.     pauseFilter = Camera.main.GetComponent(SepiaToneEffect);
    5.     PauseGame();
    6.     rotModeBuffer = mc.cameraRotationMode;
    7.     mc.cameraRotationMode = CameraRotation.None;
    8.     } else {
    9.         mc.cameraRotationMode = rotModeBuffer;
    10. }
     
  2. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    There's so if statement, why is there "} else {" ?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can't use "else" unless there's an "if" first.

    --Eric
     
  4. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Ah i see!

    Should i do something like this?
    Code (JavaScript):
    1.     function Start() {
    2.         fpsarray = new int[Screen.width];
    3.         Time.timeScale = 1.0;
    4.         pauseFilter = Camera.main.GetComponent(SepiaToneEffect);
    5.         PauseGame();
    6.         if(PauseGame;
    7.         rotModeBuffer = mc.cameraRotationMode;
    8.         mc.cameraRotationMode = CameraRotation.None;
    9.         } else {
    10.             mc.cameraRotationMode = rotModeBuffer;
    11.     }
    But i solved it like this on function pausemenu
    Code (JavaScript):
    1. function PauseMenu() {
    2.     BeginPage(200,200);
    3.     if (GUILayout.Button (IsBeginning() ? "Play" : "Continue")) {
    4.         UnPauseGame();
    5.         mc.cameraRotationMode = rotModeBuffer;
    6.         } else {
    7.         mc.cameraRotationMode = CameraRotation.None;
    8.     }

    But when i press "escape" the cam rotation is still locked and the cursor is still shown. any tips?
    Code (JavaScript):
    1. function LateUpdate () {
    2.     if (showfps || showfpsgraph) {
    3.         FPSUpdate();
    4.     }
    5.     if (Input.GetKeyDown("escape")) {
    6.         switch (currentPage) {
    7.             case Page.None: PauseGame(); break;
    8.             case Page.Main: if (!IsBeginning()) UnPauseGame(); break;
    9.             default: currentPage = Page.Main;
    10.         }
    11.     }
    12. }
     
  5. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    No, something along the lines of this
    Code (CSharp):
    1. function Start() {
    2.         fpsarray = new int[Screen.width];
    3.         Time.timeScale = 1.0;
    4.         pauseFilter = Camera.main.GetComponent(SepiaToneEffect);
    5.         PauseGame();
    6.         if(PauseGame) {
    7.             rotModeBuffer = mc.cameraRotationMode;
    8.             mc.cameraRotationMode = CameraRotation.None;
    9.         } else {
    10.             mc.cameraRotationMode = rotModeBuffer;
    11.     }
    But you seem to not know the basics of c#
    So you should really watch some tutorials, or read a book about it.

    For every bracket facing right, you need one that faces left. o.o

    Edit:
    I see that you edited your message.
    in your other script you have "if(GUILayout.Button(IsBeginning()?"Play":"Continue")){" that's why it's working.
    In your other post you added "if(PauseGame;"
    You don't put a semicolon after an if statement, and you also need to close the parentheses.
    so it should be "if(PauseGame) {"

    please learn the OOP basics for c# before trying to make a game, that's my tip...
     
    Last edited: Jun 30, 2014
  6. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    First of all. its a Java and not C# :)
    That gives no errors, but however that code function doesnt work with the script, so i had to do the coding on "function PauseMenu()

    but still the "escape" key makes me get gray hair, ESC brings up the menu and locks the cam, but when i press ESC again the menu disappear but the rotation is still locked and the cursor shows, i have to click "Continue" to get the camera rotate and even to get the cursor to disappear, i want so i can do both if you understand.
     
  7. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Re-read my post, I edited it.

    The occurences that you're describing are most likely caused by other scripts.
     
  8. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    I dont have any script that use escape key except for the pausemenu what i know.
    I know i need to have this on the right place, but i cant find out where.
    Code (JavaScript):
    1. mc.cameraRotationMode = rotModeBuffer;
    I understand you recommend reading books etc, but imagine yourself know a language not so good as the other guys that have the language as main, and then try learn coding on that language. It is not just to read, you must understand what you reading and the meaning of each word.
    Try learn DOS coding in Swedish :p
     
  9. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Well sorry, I can't seem to figure out what's causing your script to act like this.
    And it doesn't help that you aren't willing to learn the programming language s:
     
  10. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Its all about put this in at the right place
    Code (JavaScript):
    1. mc.cameraRotationMode = rotModeBuffer;
    I am willing, i "learning by doing" works best for my head.
     
  11. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    EDIT: i solved the rotation, still have the cursor left
     
    Magiichan likes this.