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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help With Game

Discussion in 'Scripting' started by Cat_cop, Aug 23, 2015.

  1. Cat_cop

    Cat_cop

    Joined:
    Aug 21, 2015
    Posts:
    5
    Hello Everyone,
    I am making a video game, and I am currently working on a 3D wave and I am using a BSplineSurface.cs script file and it is giving me a parsing error and I don't know what to do.
    Here are the details.
    It originally had 148 lines. Now it has 418.




    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4.  
    5.  
    6. using System.Collections;
    7.  
    8.  
    9. using System.Collections.Generic;
    10.  
    11.  
    12.  
    13.  
    14.  
    15. public class BSplineSurface {
    16.  
    17.  
    18.  
    19.  
    20.  
    21.   /*
    22.  
    23.  
    24. 9.  * THESE VALUES MUST BE SET BEFORE CALCULATING
    25.  
    26.  
    27. 10.  */
    28.  
    29.  
    30.   //size of the control net (e.g. 3x4 net)
    31.  
    32.  
    33.   public int NI = 4; //setting these to high can crash unity
    34.  
    35.  
    36.   public int NJ = 4;
    37.  
    38.  
    39.   //Grid of control points
    40.  
    41.  
    42.   public Vector3[,] controlGrid;
    43.  
    44.  
    45.   //The degree in each direction
    46.  
    47.  
    48.   public int TI = 3;
    49.  
    50.  
    51.   public int TJ = 3;
    52.  
    53.  
    54.   //output GRID resolution (e.g. 30x40)
    55.  
    56.  
    57.   public int RESOLUTIONI = 150; //setting these to high can crash unity
    58.  
    59.  
    60.   public int RESOLUTIONJ = 150;
    61.  
    62.  
    63.   //the output Grid
    64.  
    65.  
    66.   public Vector3[,] outputGrid;
    67.  
    68.  
    69.  
    70.  
    71.  
    72.   /*
    73.  
    74.  
    75. 26.  * INTERNAL VALUES
    76.  
    77.  
    78. 27.  */
    79.  
    80.  
    81.   //internal knots in each direction
    82.  
    83.  
    84.   private int[] knotsI;
    85.  
    86.  
    87.   private int[] knotsJ;
    88.  
    89.  
    90.   //internal variables
    91.  
    92.  
    93.   private int i, j, ki, kj;
    94.  
    95.  
    96.   private float intervalI, incrementI, intervalJ, incrementJ, bi, bj;
    97.  
    98.  
    99.  
    100.  
    101.  
    102.   //FUNCTIONS
    103.  
    104.  
    105.   private BSplineMath bmath = new BSplineMath();
    106.  
    107.  
    108.  
    109.  
    110.  
    111.   //constructor
    112.  
    113.  
    114.   public BSplineSurface()
    115.  
    116.  
    117.   {
    118.  
    119.  
    120.   Init();
    121.  
    122.  
    123.   }
    124.  
    125.  
    126.  
    127.  
    128.  
    129.  
    130.  
    131.  
    132.   //MUST BE CALLED FIRST
    133.  
    134.  
    135.   public void Init () {
    136.  
    137.  
    138.  
    139.  
    140.  
    141.   controlGrid = new Vector3[NI+1,NJ+1];
    142.  
    143.  
    144.   outputGrid = new Vector3[RESOLUTIONI, RESOLUTIONJ];
    145.  
    146.  
    147.  
    148.  
    149.  
    150.   //init step size (the increment steps)
    151.  
    152.  
    153.   incrementI = (NI-TI+2) / ((float)RESOLUTIONI - 1);
    154.  
    155.  
    156.   incrementJ = (NJ-TJ+2) / ((float)RESOLUTIONJ - 1);
    157.  
    158.  
    159.  
    160.  
    161.  
    162.   //Calculate KNOTS
    163.  
    164.  
    165.   knotsI = bmath.SplineKnots(NI, TI);
    166.  
    167.  
    168.   knotsJ = bmath.SplineKnots(NJ, TJ);
    169.  
    170.  
    171.  
    172.  
    173.  
    174.   }
    175.  
    176.  
    177.  
    178.  
    179.  
    180.   // Use this for random initialization
    181.  
    182.  
    183.   public void InitRandomGrid () {
    184.  
    185.  
    186.  
    187.  
    188.  
    189.   //init control points (random z)
    190.  
    191.  
    192.   for(i=0; i<=NI; i++)
    193.  
    194.  
    195.   {
    196.  
    197.  
    198.   for(j=0; j<=NJ; j++)
    199.  
    200.   {
    201.  
    202.  
    203.   controlGrid[i, j].x = i;
    204.  
    205.  
    206.   controlGrid[i, j].y = j;
    207.  
    208.  
    209.   controlGrid[i, j].z = Random.value;
    210.  
    211.  
    212.   }
    213.  
    214.  
    215.   }
    216.  
    217.  
    218.   }
    219.  
    220.  
    221.  
    222.  
    223.  
    224.   // Use this for grid input (remember to set NI and NJ before(the grid size) and call Init)
    225.  
    226.  
    227.   public void InitGrid (Vector3[,] inputGrid) {
    228.  
    229.  
    230.  
    231.  
    232.  
    233.   //init control points (random z)
    234.  
    235.  
    236.   for(i=0; i<=NI; i++)
    237.  
    238.  
    239.   {
    240.  
    241.  
    242.   for(j=0; j<=NJ; j++)
    243.  
    244.  
    245.   {
    246.  
    247.  
    248.   controlGrid[i, j] = inputGrid[i, j];
    249.  
    250.  
    251.   }
    252.  
    253.  
    254.   }
    255.  
    256.  
    257.   }
    258.  
    259.  
    260.  
    261.  
    262.  
    263.  
    264.  
    265.  
    266.   public void Calculate()
    267.  
    268.  
    269.   {
    270.  
    271.  
    272.   //MAIN CALCULATIONS
    273.  
    274.  
    275.   intervalI = 0;
    276.  
    277.  
    278.   for(i = 0; i < RESOLUTIONI-1; i++)
    279.  
    280.  
    281.   {
    282.  
    283.  
    284.   intervalJ = 0;
    285.  
    286.  
    287.   for(j = 0; j < RESOLUTIONJ-1; j++)
    288.  
    289.  
    290.   {
    291.  
    292.  
    293.   outputGrid[i, j] = Vector3.zero;
    294.  
    295.  
    296.   for(ki = 0; ki <= NI; ki++)
    297.  
    298.  
    299.   {
    300.  
    301.  
    302.   for(kj = 0; kj <= NJ; kj++)
    303.  
    304.  
    305.   {
    306.  
    307.  
    308.   bi = bmath.SplineBlend(ki, TI, knotsI, intervalI);
    309.  
    310.  
    311.   bj = bmath.SplineBlend(kj, TJ, knotsJ, intervalJ);
    312.  
    313.   outputGrid[i, j].x += (controlGrid[ki, kj].x * bi * bj);
    314.  
    315.  
    316.   outputGrid[i, j].y += (controlGrid[ki, kj].y * bi * bj);
    317.  
    318.  
    319.   outputGrid[i, j].z += (controlGrid[ki, kj].z * bi * bj);
    320.  
    321.  
    322.   }
    323.  
    324.  
    325.   }
    326.  
    327.  
    328.   intervalJ += incrementJ;
    329.  
    330.  
    331.   }
    332.  
    333.  
    334.   intervalI += incrementI;
    335.  
    336.  
    337.   }
    338.  
    339.  
    340.  
    341.  
    342.  
    343.   intervalI = 0;
    344.  
    345.  
    346.   for(i = 0; i < RESOLUTIONI-1; i++)
    347.  
    348.  
    349.   {
    350.  
    351.  
    352.   outputGrid[i, RESOLUTIONJ-1] = Vector3.zero;
    353.  
    354.  
    355.   for(ki = 0; ki <= NI; ki++)
    356.  
    357.  
    358.   {
    359.  
    360.  
    361.   bi = bmath.SplineBlend(ki, TI, knotsI, intervalI);
    362.  
    363.  
    364.   outputGrid[i, RESOLUTIONJ-1].x += (controlGrid[ki, NJ].x * bi);
    365.  
    366.  
    367.   outputGrid[i, RESOLUTIONJ-1].y += (controlGrid[ki, NJ].y * bi);
    368.  
    369.  
    370.   outputGrid[i, RESOLUTIONJ-1].z += (controlGrid[ki, NJ].z * bi);
    371.  
    372.  
    373.   }
    374.  
    375.  
    376.   intervalI += incrementI;
    377.  
    378.  
    379.   }
    380.  
    381.  
    382.   outputGrid[i, RESOLUTIONJ-1] = controlGrid[NI, NJ];
    383.  
    384.  
    385.  
    386.  
    387.  
    388.   intervalJ = 0;
    389.  
    390.  
    391.   for(j = 0; j < RESOLUTIONJ-1; j++)
    392.  
    393.  
    394.   {
    395.  
    396.  
    397.   outputGrid[RESOLUTIONI-1, j] = Vector3.zero;
    398.  
    399.  
    400.   for(kj = 0; kj <= NJ; kj++)
    401.  
    402.  
    403.   {
    404.  
    405.  
    406. bj = bmath.SplineBlend(kj, TJ, knotsJ, intervalJ);
    407.  
    408.  
    409. outputGrid[RESOLUTIONI-1, j].x += (controlGrid[NI, kj].x * bj);
    410.  
    411.  
    412. outputGrid[RESOLUTIONI-1, j].y += (controlGrid[NI, kj].y * bj);
    413.  
    414.  
    415. outputGrid[RESOLUTIONI-1, j].z += (controlGrid[NI, kj].z * bj);
    416.  
    417. intervalJ += incrementJ;
    418. outputGrid[RESOLUTIONI-1, j] = controlGrid[NI, NJ]; }
     
    Last edited: Aug 23, 2015
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    [code ][/code ] tags, there is a sticky at the top of the forum on them...
     
  3. Cat_cop

    Cat_cop

    Joined:
    Aug 21, 2015
    Posts:
    5
  4. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
  5. Shears

    Shears

    Joined:
    Jul 7, 2015
    Posts:
    24
    Parsing error usually mean you have too many or not enough "{" or "}"
     
  6. Cat_cop

    Cat_cop

    Joined:
    Aug 21, 2015
    Posts:
    5
    BTW It would help a lot if some1 could send a download link to the Correct File for the BSplineSurface.cs script file.

    This is very hard for me.
     
  7. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    The error will tell you what line the problem is on. What exactly is the error message you are getting?
     
  8. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Count the number of { & compare it to the # of }, a quick count looks wrong (but it's early here so I could be wrong myself). Also, is the constructor correct?
     
  9. BrendanKZN

    BrendanKZN

    Joined:
    Jun 22, 2011
    Posts:
    157
    Don't take this personally. If you want to copy and paste someone's code they provided and don't have the time to go through the code yourself and see you missed about 3 }'s towards the end of the script I'm not sure your quite ready to make video games yet. Go through the code yourself after pasting, format it correctly and you will see what your missing a mile away. Good luck.
     
  10. Cat_cop

    Cat_cop

    Joined:
    Aug 21, 2015
    Posts:
    5
    Nope didn't do that. I wrote it myself after looking at it online. What happened is it worked the first time, but then the little script editor thingy didn't save my work the second time. Then that script up above showed up.

    I can't tell if it is because my cat stepped on my F4 Key [Since I have a Lenovo laptop, the F4 key force closes the current window open.] and closed the window, or if the script editor crashed... or something..

    Still.. could someone PLEASE write this script as well as BSplineMath script and post a link to a download site for me. I am a beginner.. so I kinda might do a bad job on my game. But if someone could post a download, I will post pictures and see what you think of it SO FAR. Very little content, but I will still show pictures.
     
  11. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If you want someone to write your script for you you need to post in the collaboration thread.