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 » Scripters
Home Search
 

Re: Would this cause excess memory usage?

Previous Thread :: Next Thread 
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 03:06 PM
Say I have a function that needs to run every minute. I have two options.

One:
function myFunc()
-- code
wait(30)
myFunc()
end

coroutine.resume(coroutine.create(myFunc))


Two:
function myFunc()
-- code
end

coroutine.resume(coroutine.create(function repeat myFunc() until not wait(60) end))


The first one is my style, so naturally I want to use it. But I was thinking, if it runs fifty hundred times, it could end up using massive amounts of memory. Would that happen / is #2 better?
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 03:06 PM
Messed up on the first one's code. You know what I mean.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 03:07 PM
Golly, that's a lot of views.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
06 Apr 2013 03:08 PM
The first one could be helped by using a tail call.

return myFunc()
Report Abuse
crusada91 is not online. crusada91
Joined: 04 Sep 2010
Total Posts: 684
06 Apr 2013 03:09 PM
I don't think that would lag.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 03:11 PM
@MNN;

Didn't think of that. It doesn't look very pretty/natural, but it works. Thanks.
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
06 Apr 2013 04:27 PM
You should use the second way because if you ever want to call the function manually later in the script, you don't want it to start calling itself over and over.

If you really want to use the first way, though, then use a tail call.

_________________________________________________________________________
I possess 4 ROBUX and 73 tickets.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 04:30 PM
I have no desire to start the function's loop more than once.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
06 Apr 2013 05:13 PM
delay(0, function () --or spawn, or whatever
while wait(60) do
myFunc()
end end)
Report Abuse
8SunTzu8 is not online. 8SunTzu8
Joined: 30 Sep 2011
Total Posts: 8199
06 Apr 2013 05:25 PM
Coroutines are ugly. All of these API methods to accomplish the same thing Preh did.

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 06:01 PM
IIRC, delay waits one frame before executing. Also, what pre said is effectively the same as #2.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
06 Apr 2013 06:01 PM
Whoops

*what pre meant is effectively the same as #2.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
06 Apr 2013 06:02 PM
Yeah, if you need it to execute to-the-frame precision, go with coroutines.
Report Abuse
8SunTzu8 is not online. 8SunTzu8
Joined: 30 Sep 2011
Total Posts: 8199
06 Apr 2013 08:22 PM
lol

Coroutines just "look" ugly. I've only had to use them once before... I prefer to avoid them. Although, I seem to have issues getting parts of the API to work... Only one coroutine method worked for me. (WaitForChild() never works).

"Consider, friend, as you pass by, as you are now, so once was I. As I am now, you too shall be. Prepare, therefore, to follow me." -Scottish Tombstone Epitaph
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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