How to create a "Robot Defined" Variable

How would I go about creating a variable that is defined by the robot, not one that I type in, that I can use as a comparison value that only changes when I push a button when sensor values change?

Do you mean assigning a sensor value to a variable when you press a button on the joystick controller? Rough psuedocode for that implementation can be found below; if you are referring to a variable that is created, defined, and used by the robot automatically (without being defined in the user code beforehand), that is not possible in ROBOTC.

//Create the variable to store the sonar sensor's value
int sonarReading;

//Wait for the sonar sensor to obtain its first reading
delay(500);

//Assign the sonarReading variable its first value
sonarReading = SensorValue(sonar);

//Infinite loop
while(true)
{
	//If button 5 Down is pressed
	if(vexRT[Btn5D] == 1)
	{
		//Update the sonar reading
		sonarReading = SensorValue(sonar);	
	}
	
	//Otherwise
	else
	{
		//Other code	
	}
}