# newbie: equivalent of a static variable ?

Hello

i’m learning with the unity tutorials, and i’m trying to have a sphere move with the keys. Up to there, no problem, the sphere moves.
Now i am trying to have the keys set a “speed” variable but it seems that my speed is always at 0

var speedX = 0;
var speedZ = 0 ;

function Update( )
{

speedX = speedX +0.5 ;
speedZ = speedZ +0.5 ;

transform.Translate( speedX , 0, speedZ ) ;
}
So basically i want the sphere to get some acceleration. But it’s frozen.

Probably i’m missing something obvious
patricia.

Found my mistake,

var speedX = 0.0 ;

fixes it.
I didn’t realise that 0 was different from 0.0

patricia.

Hi Patricia,

In the Docs about the function Translate it’s mentioned that the translation has to be either from type Vector3 or x, y, z has to be from type float (floating-point number).
You wrote:

``````var speedX = 0;
var speedZ = 0;
``````

Which creates a variables of the type int (integer).
Just write:

``````var speedX = 0.0;
var speedZ = 0.0;
``````

And the variables are created as floats.

This is a bit tricky in Javascript. For example in C# you write a f behind the number and instead if var you write the type… than it’s more clear what’s meant:

``````float speedZ = 0f;
``````

You can find out which type a variable is like this:

``````speedZ.GetType();
``````

And print it in the console with the Debug.Log():

``````function Start()
{
Debug.Log("The Variable speedZ is of the type: " + speedZ.GetType());
}
``````

If you don’t specify a type JavaScript infers the type from the assignment.
Thus
var x = 0; gives you an integer
where
var x = 0.0; gives you a float.

You can specify it explicitly by writing:
var x : float = 0;
or
var x : float = 0.0;
Which is now equivalent for because of the explict type assignment.

Thanks, i was actually wondering how to define a type for a variable.

Patricia.