Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

An alternative to While True Do?

Hello all!

I'm scripting a rather large game, but for one portion of it, I need to have a 'rounds' script running:

while true do	
local roundtime = 500
for i = roundtime, 0, -1 do
	if i == 0 then 
-- Do Stuff
end

I'm trying to make my game as memory efficient as I can, and I've found that while true do scripts tend to add MB to the memory usage, this particular one by itself adds 50-75MB of memory on desktop computers.

Question - Is there a better way to utilize a 'rounds' script than while true do, that's more memory efficient?

Thanks!

3 comments

0

seems fine to me. you're looping for a reason and it's not needless comparisons as far as I know

0

im.not really that experienced but couldn't you use a module script and call it whenever you want?

0

While true do loops adds to the memory use, trying to trim as much as I can. :)

1 answer

✓ Accepted answer

You shouldn't worry about efficiency right now because a single loop does scarcely anything, if you are trying to use an alternative, try these.. 1,

for i = 1,100,1 do
print(i)
end
local a = 0
repeat wait()
print(a) a = a+1
until a > 99
local a = 0
local function iterate()
	a = a + 1
	print(a)
	if a > 99 then else iterate() end
	wait()
end
iterate()

7 comments

0

I do have to worry about efficiency, consolidating game modes into one, I've got my memory usage down to 750MB, but this script alone adds 50-75 of MB to the memory use. I'm at the point that I'm trying to find every way I can to cut down.

0

I'll try methods out. Thanks! :)

0

In the grand scheme of things, MB is tiny these days relative to the GB's of memory used. Without running my game, the current game I have, just with studio open, is taking up 3GB of space. I wouldn't split hairs over MB's, but definitely, you should have a good method for handling rounds in your game. A round based game in the Roblox Studio templates, you might take a look at, as well.

0

Agreed, but when your game needs to run on low end laptops and smart phones, it needs to be built to scale. :) I appreciate the response. My post put too much emphasis on the Rounds portion, its the while true do, that I really need efficient alternatives to.

0

repeat (...) until false is quite literally the same exact thing as while true do

0

lua leaves a small footprint anyway...

0

If you need anything else just ask c:

This discussion is preserved as it was. New answers, comments, and votes are closed.