generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Whats more efficient

Previous Thread :: Next Thread 
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
20 Nov 2013 10:26 AM
Last word I meant vas variable.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
20 Nov 2013 10:56 AM
When I take out the return I get the error you were talking about
Report Abuse
zars15 is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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 is not online. 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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
20 Nov 2013 02:20 PM
It only stack overflows without a wait
Report Abuse
zars15 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image