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

Why does the While true do function lag online?

Asked by 8 years ago

Why does the function while true do seem to lag online now?

Is there a more effective substitute?

0
while true do is not the function itself (better call it a statement). While is the statement. We put true so we can loop our things easily. It is not deprecated, and the only way it could get deprecated is if the whole While statement got deprecated (which would ruin Lua all together). Are you sure it doesn't lag just for you? Marios2 360 — 8y

1 answer

Log in to vote
1
Answered by
Unclear 1776 Moderation Voter
8 years ago

First, while true do is not a function. That is a combination of a loop declaration (of the while type), and a conditional statement (which is what true is).

Thus, while true do is nothing more than just the declaration of a while loop that continues until its condition becomes equivalent to false. Since true is never false, your loop will never end.

But that's besides the point.

Loops will never create perceivable latency. Never. They are what is commonly known as a control flow statement, which only redirect the natural flow of code. In the case of loops, if the loop's condition is true then it redirects the flow of the code back to the start of the loop.

What creates latency are the contents.

So let's ignore the loop portion of your code and look at what's remaining... wait() and print'hello world'. Your culprit is right there: the print statement should not be abused and should only be used sparingly because writing to the output is an expensive operation.

This means that it is more likely to take up considerably more computer resources than anything else, and since you're writing to the output literally every single opportunity you can, you shouldn't be surprised that your print statements are eating up your computer's resources, bit-by-bit.

0
You should also mention that if you have a loop and you don't add a wait, it would lag. EzraNehemiah_TF2 3552 — 8y
Ad

Answer this question