- Home /
Can I do recursion in unity3d compiler using javascript?
Can I do recursion in unity3d using javascript? Here is my code:
function Start () {
RefreshPing();
}
function RefreshPing():void{ //call ever 5 sec
if(Network.isServer){
for(var i:int=0;i<64;i++){
if(PlayerBool[i]){
var j : int=Network.GetAveragePing(GameingNetWorkPlayer[i]);
networkView.RPC ("NewPing",RPCMode.All,i,j);
}
}
}
yield WaitForSeconds(5);
RefreshPing();
}
Comment
Answer by sniper43 · Jan 16, 2015 at 01:14 PM
This is a horrible idea, as individual functions will never leave the stack. Better to use
while(bool) RefreshPing();
EDIT: to further elaborate3 on this: at the end of RefreshPing() you call it itself. The function then has to SAVE itself and run the newly invoked function. And so it runs a copy of itself while still being active.
This is how memory leaks are made.
Your answer
Follow this Question
Related Questions
Call a function once from OnGUI 2 Answers
NullReferenceException: Object reference not set to an instance of an object 2 Answers
Calling IEnumerators 1 Answer
Why doesen't the function get called the second itme? 1 Answer
How to call functions? 1 Answer