Cannot declare variable in static function at win7

Forgive my English is very poor :smile:
I have a project at Mac and it runs well,but when I moved it to my pc(win7), there are a lot of errors. Then I find that at win7, If I declare variable in static function, the console shows errors,but when I declare this variable out of function and use static,is ok.

for example
it can runs well at mac,but error at win7

public static Vector3 getFighterAcceleration()
	{
		
		Vector3 accelerator = Vector3.zero;		
                return accelerator;
	}

If I code like this,it can run at win7

static Vector3 accelerator ;
public static Vector3 getFighterAcceleration()
	{
	       accelerator = Vector3.zero;		
               return accelerator;

	}

Is there something wrong with my .net framework at win7?

This code should works well.
Can you quote an error mesage and line number where it thrown?

The error message is
error CS0103: The name `accelerator’ does not exist in the current context

When I double click the error message, it goes to the MonoDevelop but locates a wrong line which is a blank line.

Hm, it’s strange. I’ve just check it on my Win7 PC with Visual Studion 2010, and this works fine.
In any case, try to rewrite in one of these ways:

public static Vector3 getFighterAcceleration()
        {
             return Vector3.zero;    
        }

or

public static Vector3 getFighterAcceleration()
    {
        Vector3 accelerator = new Vector3();
        return accelerator;
    }

I doubt this is Win7 issue. (Anything is possible of course :slight_smile: ). I actually share the same project between 3 PCs. 2 of them running Win 7 and 1 of them is on XP. Never had any problems like this. Monodevelop has problems sometimes but they usually go away after restart. Maybe publish code for your whole class? Maybe something wrong beyond this one method that you are looking at?

I think I find the reason. At mac I have same comment code using Chinese characters but at win7 they cannot be distinguish. So I delete all Chinese characters and it works. It’s strange. However, thank you very much! :smile:

code:
public static Vector3 getFighterAcceleration()
{
//获取重力
Vector3 accelerator = getAccelerator2();
accelerator = Quaternion.Euler(new Vector3(0,0,-90))*accelerator;
// Debug.Log(“accelerator=” + accelerator);
//-0.3 ~ 0.3
float offsetAccelerator = getOffsetAccelerator2(accelerator);
float offsetAcceleratorHorizon = getOffsetAcceleratorHorizon(accelerator);

return new Vector3(offsetAccelerator, offsetAcceleratorHorizon, 0);
}
The reason is the Chinese characters such like “//获取重力感应值”. When I delete all Chinese characters it works at win7. But It can works at mac,don’t know why…

Yeah, right! :stuck_out_tongue: I think the reason is the Chinese characters - compiler requires an EndOfLine symbol before declaration of new variable.

you can change

//获取重力
Vector3 accelerator = getAccelerator2();

to (just add new line before Vector3):

//获取重力

Vector3 accelerator = getAccelerator2();

Can I set the monoDevelop of win7 to adapt these Chinese characters? This project has too many Chinese characters:(

It seems MonoDevelop does not support chinese characters. I can only suggest to write an utility tool that will parse code files and add “\r\n” (EndOfLine symbols) after each chinese comment. :neutral:

OK,I will remember this next time.