- Home /
Functions overwrite or work seperatelly ?
Ok i have a question that has been bothering me and i dont know how to search it or google it cause i cant express it, So my problem is if i make a custom funtion like:
var bb : int[];
function Update () {
if (input.getkeyDown("W") {
CustomF ();
}}
function CustomF () {
for (var i = 0; i < 10000; i++) {
bb[i] = i;
}
Debug.Log (bb);
}
yes this is an untested code i just wrote to simulate what i mean, will the bb ever colapse with a previous version of itself or is the function CustomF in a different dimention when and doesnt colide with previous calls of itself ? (excluding functions like Start,Awake,Update ect.)
Answer by erick_weil · Feb 15, 2014 at 02:25 PM
you are modifying the bb var, if you acess the bb a new time before call your customf function your variable bb will be modifyied.
to the main variable not changes use this :
var bb : int[];
function Update () {
if (input.getkeyDown("W") {
CustomF (bb);
}}
function CustomF (localbb : int[]) {
for (var i = 0; i < 10000; i++) {
localbb[i] = i;
Debug.Log (localbb[i]);
Debug.Log (bb[i]);
}
}
hmm thats what i thought but doing this will create GC and this is supposed to be on a server with a much more complicated structure but it seems that there isnt any other way or is it ?
Actually this works well since i am not creating a new variable in the function (= no GC) but having a parameter will work just fine, wont it ? If anyone has any rejections let me know cuase this might work on my case.
Your answer
Follow this Question
Related Questions
javascript equivalent of Action? 0 Answers
BCE0044: expecting (, found 'OnGUI'. 1 Answer
Performance Optimization ~Function Update: Loop or Once ? 5 Answers
Adding an offset to an instantiated objects rotation 0 Answers
Can I use Javascript (Unityscript) for Box2D for Unity or Farseer Physics? 1 Answer