- Home /
function inside function or while loop (javascript)
This has been bothering me for some time. I have some code that is in a function. After so many seconds the function repeats itself. I do this by calling the same function. I've had one person on this site called it "fugly logic". An example of what I am doing is
  function myFunction(): IEnumerator {
         //some code
         yield WaitForSeconds(3)
         myFunction()
     }
 
Is their any performance issues with doing this. I know their are more official ways of repeating things but I don't see any problem with this. Although another person suggested that I should do
 while (true) {
 function myFunction(): IEnumerator {
     //some code
     yield WaitForSeconds(3)
 }
 
Would this or the first one be better? Or is their something totally different that would be worth changing my code to it?
Answer by whydoidoit · Mar 02, 2014 at 06:14 AM
Ok that suggested way of doing it - do not do it like that. Unity Javascript isn't real Javascript and that stuff doesn't play well. But yes, you should probably do it as a while loop formatted like this:
    function myFunction() : IEnumerator {
           while(true) {
                 //some code
                 yield WaitForSeconds(3);
           }
    }
Your answer
 
 
             Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
First person shooter shoot Function 3 Answers
running code outside of update! 3 Answers
Call function from other script 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                