Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

An alternative to While True Do?

Asked by 5 years ago

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!

0
seems fine to me. you're looping for a reason and it's not needless comparisons as far as I know royaltoe 5144 — 5y
0
im.not really that experienced but couldn't you use a module script and call it whenever you want? seikkatsu 110 — 5y
0
While true do loops adds to the memory use, trying to trim as much as I can. :) Never2Humble 90 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

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

2.

local a = 0
repeat wait()
print(a) a = a+1
until a > 99

3.

local a = 0
local function iterate()
    a = a + 1
    print(a)
    if a > 99 then else iterate() end
    wait()
end
iterate()
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. Never2Humble 90 — 5y
0
I'll try methods out. Thanks! :) Never2Humble 90 — 5y
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. JasonTheOwner 391 — 5y
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. Never2Humble 90 — 5y
View all comments (3 more)
0
repeat (...) until false is quite literally the same exact thing as while true do DeceptiveCaster 3761 — 5y
0
lua leaves a small footprint anyway... EmbeddedHorror 299 — 5y
0
If you need anything else just ask c: greatneil80 2647 — 5y
Ad

Answer this question