|
| 20 Nov 2013 10:03 AM |
For a script that runs all the time while wait(1) do print("Game stuff") end
Or
function start() wait(1) print("Game stuff") return start() end start() |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 Nov 2013 10:13 AM |
| Loop, because recursion isn't infinite, and will eat up RAM. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 10:17 AM |
Why is it not infinite? And why does it eat ram if return ends the function everytime? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 Nov 2013 10:24 AM |
| It returns the returned value by function and so on. Recursion is limited, because it needs to keep the function in memory, so it can return the returned function. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 Nov 2013 10:26 AM |
| Last word I meant vas variable. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 10:33 AM |
Im testing it and it doesn't seem to be limited, it works fine I think its limited without waits, and also my return should end the function so like its not like its Start function >Start function >>Start function >>>Start function
Its Start function >Start function, end last >Start function, end last >Start function, end last
Or am I wrong?
|
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 10:56 AM |
| When I take out the return I get the error you were talking about |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 Nov 2013 11:11 AM |
| Even if that works, while loop would be faster, since in assembly it would just test the value, and jump, while functions are more complicated than loops. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 11:24 AM |
Okay, is there a way to stop the while loop in the middle of it running? Like while wait(0.03) do if true then break end end
I want it to start the loop over though not just end it |
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 20 Nov 2013 02:16 PM |
I'm pretty sure the start() will (as that other person) said break sometime. Try this: function t() t() end t() Result: stack overflow I think that also happens with a delay, but just way later
Made some code to test it:
local f = {} for i=1,99 do f[i] = function() f[i+1]() end end f[100] = function() wait() f[1]() end f[1]()
After less than a minute (for my machine, can depend I think) it stack overflows. Myth busted. (As you see, f[100] has a wait() :D) |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 02:20 PM |
| It only stack overflows without a wait |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 Nov 2013 03:41 PM |
Only way to have the loop run again, is to have a loop for it too.
while true do while wait(0.03) do if true then break end end end
Well but it really depends for what you need it. You might also put it into a function, and run it in new thread. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2013 03:49 PM |
| Returning from a function adds the value to the execution stack in memory. If you run out of memory, you cannot add to the execution stack, and you will receive a stack overflow error. |
|
|
| Report Abuse |
|
|