How do I call defined variables within a function? (CS0103)

Hi All,

After bashing my head against a brick wall - and a lot of googling - I’ve decided it’s time I swallow my pride and ask for help!!

I’ve written some code which will increase/decrease a variable if it’s different from the “requested” variable, essentially like the accelerator on a car.

I wrote a function to do this - however, it relies on variables which are defined further up in the script. For whatever reason, I can’t call this variables in my function - as unity/mono things they don’t exist! (Which they probably don’t…)

Code is written in C#

float RPMportOUT = 0.0f;
float total = 0.0f;
public float RPMPGAINP = 0.0f;
public int portRPMACT = 0;
float REQRPMP = 0.0f;
public Telegraph tele;
	
	// Use this for initialization
	void Start () {	
	tele = GameObject.Find("MainShip").GetComponent<Telegraph>();
}
	
	// Update is called once per frame
	void Update () {
}
	void fixedupdate ()
	{
}

	void engineRPM()
	{
		if (portRPMACT = REQRPM)
		{
			total = portRPMACT;
		}
		else {
			if (portRPMACT < REQRPM)
			{
				total = portRPMACT + RPMGAINP;
			} 
		else {
			if (portRPMACT > REQRPM)
			{
				total = portRPMACT - RPMGAINP;
			}
			return RPMportOUT = total;
			}
		}
	}
}

Thanks in advance!

total = portRPMACT;

total is not declared in the posted code?

return RPMportOUT = total;

but the function is marked void

public float ThisFunctionReturnsAFloat () {

 return 2134.0f;

}

fill in the blanks :slight_smile: