Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

  private bool fillRandomBlock (ref int x, ref int y, ref int z, ref int newNumber) {
   List emptyBlocks = this.getEmptyBlocks();
   int emptyIndex;
   BlockScript blockScript;

   if (emptyBlocks.Count > 0) {
    emptyIndex = Random.Range(0, emptyBlocks.Count);
    if(this.options.use_0) {
     newNumber = Random.Range(0,3) * 2;
    }
    else {
     newNumber = Random.Range(1,3) * 2;
    }
    this.setBlockNumber(emptyBlocks[emptyIndex], newNumber);
    blockScript = emptyBlocks[emptyIndex].GetComponent("BlockScript") as BlockScript;
    x = blockScript.x;
    y = blockScript.y;
    z = blockScript.z;
    return true;
   }

   //no empty blocks to return
   return false;
  }