Keeping old GameObject values

(question has been answered)

I have this code...

var selected : boolean;
var selectedObject : GameObject;
var oldObject : GameObject;
var xcoord : float;
var zcoord : float;

function Update()
{
    if(selectedObject != null)
    {
        xcoord = selectedObject.transform.position.x;
        zcoord = selectedObject.transform.position.z;

    if(selectedObject.tag == "Unit")
        {
            print(selectedObject.name + " selected");
            oldObject = selectedObject;
        }

        if(selectedObject.tag == "Tile")
        {
            if(oldObject.tag == "Unit")
            {
                print("went through");
                /*oldObject.transform.position.x = xcoord;
                oldObject.transform.position.z = zcoord;*/

                selectedObject = oldObject;
            }
        }
    }
}

The problem is that 'went through' is never being printed. It seems that oldObject is not keeping its tag. Help please? I don't want to just reassign the tag, as I want it to keep its other components as well.

Edit: I put in the entire script to make it more readable. Edit2: Apparently something went wrong with my tagging, and it works now. The code above is (except for the null reference exception) fine.

If you're just moving an object reference around, that code above should work. The problem I think is you might not be explicitly declaring oldObject outside of your function, so it would know to hang on to its value. Your code would still work in javascript, but it might think oldObject is a local variable (hence the value gets dumped as soon as the function is done, and not what you expected the second time around)