Locking the value of a variable, or something similar

So I’m writing a program and have run into a problem with variables.

var someArray : array;
var someVar : CustomClass;

function Update()
{
   var tempVar = someVar;
   someArray.Push(tempVar);
   //call a function which resets someVar
}

What I want is for ‘tempVar’ to be put into the array with the values that ‘someVar’ has during that particular moment. But after I put it into the array it keeps updating itself to whatever the current value of ‘someVar’ is. How do I make this do what I want it to?

Your code worked for that, but when I tried to apply the same technique to a scaled down version of the code I’m working with it didn’t work and the values I was trying to save were erased when I cleared the var ‘action’.

var action : ActionClass;
var actionArray : Array = new Array();
var num: int = 0;



function resetAction() // reset all properties for action to default
{
	action.doer = null;
	for(var i :int = 0; i < action.target.length; i++)
		{
			var resetTarget : CharacterClass = action.target*;*
  •  	action.target.RemoveAt(i);*
    
  •  	resetTarget.targeted = false;*
    
  •  	i -= 1;*
    
  •  }*
    
  • action.target.Clear();*
  • action.actionType = “”;*
  • action.attackAction = null;*
  • action.stage = “building”;*
    }

function Update()
{

  • num++;*
  • action.actionType = “”+num;*
  • var tempAction : ActionClass = action;*
  • actionArray.Push(tempAction);*
  • resetAction();*
  • for(var i:int = 0; i < actionArray.length; i++)*
  • {*
    _ var tempActionInfo : ActionClass = actionArray*;_
    _
    Debug.Log(tempActionInfo.actionType);_
    _
    }_
    _
    }*_

Well I don’t know the types of your variables, but I think that you can try to make a “clone” of your variable. For example, let be a Vector3, instead of just attribute the variable with the tempVar, you can make tempVar be a new Vector3 and just copy its informations .

var someArray : array;
var someVar : Vector3;

function Update()
{
   var tempVar : Vector3 = Vector3( someVar.x, someVar.y, someVar.z ); // Change here
   someArray.Push(tempVar);
   //call a function which resets someVar
  ...
}