got problem with x's position!

Trying to get the position of an Instance from one code. Here goes my first code:-

var redCube: GameObject;
var blueCube: GameObject;
var currentCube: GameObject;

var thegrid = new int[7,5];

var cubeSwitch: boolean = false;
var flag:boolean = false;
currentCube=redCube;

function Start()
{

	Instantiation();	

}


function Update()
{	
	
 	if(Input.GetKeyDown(KeyCode.Space))
 	{
 		if(currentCube==redCube)
 		{
 			currentCube=blueCube;
 		}
 		
 		else if(currentCube==blueCube)
 		{
 			currentCube=redCube;
 		}
 		
 		Instantiation();
 		
 	}
 	
 	
Debug.Log(currentCube.GetComponent(forCube).transform.position.x);
	
	
}



function Instantiation()
{
		Instantiate(currentCube, Vector3(0,0,0),Quaternion.identity); 
		
}

There is one more code, which is attached to cubes. And that is:-

var flag: boolean = false;
var control:boolean=true;

function Update () 
{
if(control)
{

if (Input.GetKeyUp(KeyCode.LeftArrow)&&transform.position.x>-3)
  {
//  	Debug.Log("left arrow");
  	transform.position.x--;
  }
  
  else if
  (Input.GetKeyUp(KeyCode.RightArrow)&& transform.position.x<3)
  {
   transform.position.x++;
  }
  
  if(Input.GetKeyDown(KeyCode.Space))
  {
  	flag=true;
  	control=false;
  }
  
 } 
  if(flag)
  {
  		if(transform.position.y>-5)
  		{
  		
  		transform.position.y--;
  		
  		}
  }

}

According to my first code the cube get instantiated at 0,0,0 positions but in the log screen it shows -10 for once then 0 then -10 then 0, per instantiation. Can anyone please tell me where have I gone wrong???

Could you describe your project more? Is it like Tetris or are you pre-populating a grid?

You get the x coord of anything by getting its transform. Ex:

 currentCube.transform.position.x

Your code will create a new red or blue cube at 0,0,0 every frame. My guess is one of your red or blue prefabs has a -10 and the other has 0.

This code:

currentCube.GetComponent(forCube).transform.position.x

would be better as

currentCube.transform.position.x

" In-order to find which column the cube should fall I need to know the x-position."
x-position of what exactly? Your cubes are either at zero or -10 when created. It really seems like there needs to be more interaction here, like with the mouse or keys or time or something. Creating 60+ cubes per second without stopping, that’s a memory leak.

The instantiated value dosen’t have the instance. This was my problem. Here are the things that I changed/added:-

var extraCube:GameObject; // a variable to store the Instantiated value.

then, in function Instantiation:-

function Instantiation()
{
       extraCube=Instantiate(currentCube, Vector3(0,0,0),Quaternion.identity); 

}

now in the main program:-

Debug.Log(extraCube.GetComponent(forCube).transform.position.x);