- Home /
how to pass an int to a function by reference in Javascript ? (as an InOut parameter)
I've got this function:
static function GetSpawnPos (prevSpawn:int, y:float) : Vector3
{
//stuff happens here
//I read prevSpawn and change it's value sometimes
}
I want prevSpawn integer to be passed by reference, so that the original integer that is passed to this function is modified when I modify prevSpawn.
How do I do this in Javscript ? (cause I can't seem to find how to declare an int pointer)
Answer by Jessy · Jan 22, 2011 at 02:31 PM
As far as I know, this never became possible. Wrap it in a class or switch to C#.
http://forum.unity3d.com/threads/4213-Javascript-Reference-Variables
I used JavaScript in Unity for a couple years (because all of the tutorials and documentation used it, and I never programmed before Unity) and switched to C# due to JS's limitations. Coding has been much easier and more enjoyable for me since then, so I'd recommend it. What is pf?
pf is a sound (basically like sighing) :) Do you know wether vectors (vector3 and the like) are also passed by value? cause it appears that way.
Yes. If the docs say it's a struct, it's passed by value. If the docs say it's a class, it's passed by reference. This is not Unity-specific, if you were wondering.