Search Unity

parsing error but cannot see how to fix it?

Discussion in 'Scripting' started by Greggy, Jan 18, 2014.

  1. Greggy

    Greggy

    Joined:
    Aug 11, 2013
    Posts:
    7
    i have a parsing error with the very last symbol of the code how can i fix this?

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Generator : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         GenerateChunks();
    9.     }
    10.    
    11.     void GenerateChunks()
    12.     {
    13.         Vector3[] chunks = new Vector3[render_distance*render_distance];
    14.         bool[] chunksbool = new bool[render_distance*render_distance];
    15.        
    16.         int i = 0;
    17.        
    18.         for(int x=(render_distance/2)*-1;x<render_distance/2;x++)
    19.         {
    20.             for(int z=(render_distance/2)*-1;z<render_distance/2;z++)
    21.             {
    22.                 int px = Mathf.RoundToInt(player.transform.position.x /16) * 16;
    23.                 int pz = Mathf.RoundToInt(player.transform.position.z /16) * 16;
    24.                 px = px+(x*16);
    25.                 pz = pz+(z*16);
    26.                 chunks[i] = new Vector3(px,0,pz);
    27.                 chunksbool[i] = true;
    28.                 i=i+1;
    29.             }
    30.         }
    31.        
    32.         for(i=0;i<render_distance*render_distance;i++)
    33.         {
    34.             foreach (Transform child in transform)
    35.             {
    36.                 if(child.transform.position == chunks[i]) { chunksbool[i]=false;
    37.                    
    38.                 }
    39.             }
    40.         }
    41.         for(i=0;i<render_distance*render_distance;i++)
    42.         {
    43.             if(chunksbool[i])
    44.             {
    45.                 CreateChunk(chunks[i]);
    46.             }
    47.         }      
    48.     }
    49.  
    50.     void CreateChunk(Vector3 pos)
    51.     {
    52.         Transform chunk = Instantiate(Chunk,pos,Quaternion.identity) as Transform;
    53.         chunk.transform.parent = transform;
    54.        
    55.     }
    56.     void DestroyChunks()
    57.     {
    58.         int px = Mathf.RoundToInt(player.position.x/16) * 16;
    59.         int pz = Mathf.RoundToInt(player.position.z/16) * 16;
    60.         int renderer = Mathf.RoundToInt(render_distance + (render_distance/2));
    61.        
    62.        
    63.         foreach (Transform child in transform)
    64.         {
    65.             Vector2 ch = new Vector2(child.transform.position.x,child.transform.position.z);
    66.             Vector2 pl = new Vector2(player.transform.position.x,player.transform.position.z);
    67.            
    68.            
    69.             float dist = Vector2.Distance(ch,pl);
    70.            
    71.             if(dist>renderer*20)
    72.             {
    73.                 Destroy(child.gameObject);
    74.                
    75.             }  
    76.         }
    77.     }
    78.     // Update is called once per frame
    79.     void Update () {
    80.        
    81.         GenerateChunks();
    82.         DestroyChunks();
    83.         {
    84.  
    85.     }
     
  2. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    564
    You're not likely to get much help unless you show the specific error you're getting (cut and paste it). It should contain some detailed info that'll help in resolving the problem.

    Jeff
     
  3. Greggy

    Greggy

    Joined:
    Aug 11, 2013
    Posts:
    7
    it is literally saying error CS8025: parsing error for this line here

    // Update is called once per frame

    void Update () {



    GenerateChunks();

    DestroyChunks();

    {



    }
     
  4. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    You have 2 open brackets in your update method and only one close bracket.
    There has to be a close bracket for every open bracket.
     
  5. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    As Ingot said, you have two opening brackets and only one closing bracket.

    Also, regarding your PM, you can post in one of the links in my signature if you have any Cubiquity-specific questions. Obviously general scripting questions such as this one belong here.
     
  6. Greggy

    Greggy

    Joined:
    Aug 11, 2013
    Posts:
    7
    i removed it so there was 1 open bracket but its still giving me the exact same error
     
  7. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    Sorry, my mistake. The closing bracket was actually for the class (not the function) so you do need it. But your second opening bracket is pointing the wrong way as it should be a closing bracket for the function.

    Basically, you'll make your life easier if you use consistent indentation so you can see which brackets are paired up. The code below fixes your parse error, but it still doesn't compile for me (e.g. render_distance is not defined). But you probably know how to fix this.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. public class Generator : MonoBehaviour
    6. {
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.         GenerateChunks();
    11.     }
    12.  
    13.     void GenerateChunks()
    14.     {
    15.         Vector3[] chunks = new Vector3[render_distance*render_distance];
    16.         bool[] chunksbool = new bool[render_distance*render_distance];        
    17.  
    18.         int i = 0;
    19.  
    20.         for(int x=(render_distance/2)*-1;x<render_distance/2;x++)
    21.         {
    22.             for(int z=(render_distance/2)*-1;z<render_distance/2;z++)
    23.             {
    24.  
    25.                 int px = Mathf.RoundToInt(player.transform.position.x /16) * 16;
    26.                 int pz = Mathf.RoundToInt(player.transform.position.z /16) * 16;
    27.                 px = px+(x*16);
    28.                 pz = pz+(z*16);
    29.                 chunks[i] = new Vector3(px,0,pz);
    30.                 chunksbool[i] = true;
    31.                 i=i+1;
    32.             }
    33.         }    
    34.  
    35.         for(i=0;i<render_distance*render_distance;i++)
    36.         {
    37.             foreach (Transform child in transform)
    38.             {
    39.                 if(child.transform.position == chunks[i])
    40.                 {
    41.                     chunksbool[i]=false;  
    42.                 }
    43.             }
    44.         }
    45.  
    46.         for(i=0;i<render_distance*render_distance;i++)
    47.         {
    48.             if(chunksbool[i])
    49.             {
    50.                 CreateChunk(chunks[i]);
    51.             }
    52.         }    
    53.     }
    54.  
    55.  
    56.  
    57.     void CreateChunk(Vector3 pos)
    58.     {
    59.         Transform chunk = Instantiate(Chunk,pos,Quaternion.identity) as Transform;
    60.         chunk.transform.parent = transform;  
    61.     }
    62.  
    63.     void DestroyChunks()
    64.     {
    65.         int px = Mathf.RoundToInt(player.position.x/16) * 16;
    66.         int pz = Mathf.RoundToInt(player.position.z/16) * 16;
    67.         int renderer = Mathf.RoundToInt(render_distance + (render_distance/2));
    68.  
    69.         foreach (Transform child in transform)
    70.         {
    71.             Vector2 ch = new Vector2(child.transform.position.x,child.transform.position.z);
    72.             Vector2 pl = new Vector2(player.transform.position.x,player.transform.position.z);
    73.            
    74.             float dist = Vector2.Distance(ch,pl);
    75.            
    76.             if(dist>renderer*20)
    77.             {
    78.                 Destroy(child.gameObject);
    79.             }  
    80.         }
    81.     }
    82.  
    83.     // Update is called once per frame
    84.  
    85.     void Update ()
    86.     {
    87.         GenerateChunks();
    88.         DestroyChunks();
    89.     }
    90. }