vRaphy
(Rox)
July 1, 2021, 2:57pm
#1
I have been seeing a lot of people doing:
while true do
wait(1)
print("printing with cooldown")
end
But I always do:
while wait(1) do
print("printing with cooldown")
end
I don’t understand why people don’t replace true
with wait()
. I want to know if I’m doing a bad practice or not. Is there a good reason to do the first one instead of second one? Does it give better performance?
1 Like
For me i prefer useing while wait() do instead of while true do wait()
1 Like
rtvr56565
(rtvr56565)
July 1, 2021, 2:59pm
#3
It’s differents ways to script, the important is if works or not
1 Like
i dont think there is diffrence people just prefer the first one
1 Like
vRaphy
(Rox)
July 1, 2021, 2:59pm
#5
Thanks, I was confused if I was doing something stupid or not xD
1 Like
D0RYU
(nici)
July 1, 2021, 3:01pm
#6
this only works because of what wait() returns
I’ve been told that this is less safe, but it’s actually perfectly safe(most of the time) because apparently wait() won’t change what it returns
I made a post about this exact thing
not exactly what I was meaning to say, if you do
game:GetService(“RunService”).HeartBeat:Connect(function()
end)
this runs every frame(a specific part of the frame ik that) and it won’t wait for the code inside to finish to run again
a loop waits for the code inside to finish in order to run again
that’s the difference
EDIT: I can’t seem to put the code into format sorry
2 Likes
angrybino
(angrybino)
July 1, 2021, 3:02pm
#7
@rtvr56565 Reply’s is incorrect - Prefer the latter in a rare case where wait()
doesn’t return anything, resulting in the while loop’s evaluation to result in not a truthy value, which will cause it not to run of course.
You expect your while loop’s evaluation to be always truthy if you want it to be. Hence why while wait()
evaluation can possibly be unsafe.
1 Like
I don’t remember what topic I saw this in. But, a Developer Engagement member concluded that while wait() do
is safe.
vRaphy
(Rox)
July 1, 2021, 3:39pm
#9
Some says safe and some don’t? Welp.
D0RYU
(nici)
July 1, 2021, 3:42pm
#10
this was said in my post by someone who knows what they are talking about, I think it’s safe enough to use
1 Like
That may be true, but this is also important:
This is an adaptation of a Twitter thread I made a while ago. This is simply a better formatted and more fleshed out version.
Let’s talk about wait(). Not wait(n) (although if you are using small n values to where it’d be barely distinguishable from wait(), you’re probably going to hit the same issues mentioned in this thread).
We probably learned about wait() at first as the solution to “why are my infinite loops crashing me?”. It’s a super easy solution and it works! This starts a bad habit…
1 Like
D0RYU
(nici)
July 1, 2021, 4:40pm
#12
this is between while true do wait() and while wait() do
obviously wait() is bad practice but it’s good to know the difference between the two
1 Like
system
(system)
Closed
September 25, 2023, 5:07pm
#13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.