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 » Scripting Helpers
Home Search
 

Re: How does while wait() do even work?

Previous Thread :: Next Thread 
shadostriker is not online. shadostriker
Joined: 07 Aug 2008
Total Posts: 7860
26 Sep 2012 03:43 PM
wait() isnt really anything that could be identified as true or false..
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
26 Sep 2012 03:45 PM
Think of it this way,

wait() is not false. So since it's not false it's true.

It's basically

while true do
--code
wait()
end

Report Abuse
Mathfreak231 is not online. Mathfreak231
Joined: 21 Jun 2010
Total Posts: 5311
26 Sep 2012 03:47 PM
It returns both 1. wait time since it was called and 2. game time in total

Which is neither false nor nil, no matter how many times you call it.

So the loop runs infinitely, while also waiting 1 frame between each run.

FAILC ORBAS!
Report Abuse
TheNewRobloxMan41800 is not online. TheNewRobloxMan41800
Joined: 16 Jul 2012
Total Posts: 65
26 Sep 2012 05:25 PM
Wait (# of seconds) it's like waiting, The number of seconds!
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
26 Sep 2012 05:27 PM
The wait() function returns two numbers which are evaluated by the while loop. Since the returned values are neither false nor nil, it evaluates to true and continues the loop.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
26 Sep 2012 05:55 PM
while wait() do
print("Hi")
end

is the equivalent of

while true do
print("Hi")
wait()
end
Report Abuse
Xlaive is not online. Xlaive
Joined: 25 Aug 2012
Total Posts: 97
26 Sep 2012 05:59 PM
>     while wait() do
>     print("Hi")
>     end
>     is the equivalent of
>     while true do
>     print("Hi")
>     wait()
>     end

Not necessarily. In your examples, there's a difference. If you raise the wait, you'll see it.
Report Abuse
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
26 Sep 2012 06:01 PM
Yeah, I think the Wait() should be on top of the code.

Haters gonna hate
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
26 Sep 2012 06:09 PM
Copied from the LuaLearners tutorial on "Truthiness" by Ozzypig.

Truthiness (or better, "whether or not a value is truthy") is the determination of whether or not a value is truthy. The simplest way to do this is to throw the value in an if-statement. For example, if we wanted to check if "true" was truthy, we could do this:

v = true
if v then
print(tostring(v) .. " is truthy")
else
print(tostring(v) .. " is not truthy")
end

Of course, this prints "true is truthy". Notice how we did not use "== true" in that if-statement. We are not checking if the value is true, we are checking if it is truthy. There's a difference. The == operator returns either "true" or "false". Let's check a different value, say, the number 5.

v = 5
if v then
print(tostring(v) .. " is truthy")
else
print(tostring(v) .. " is not truthy")
end

This prints "5 is truthy". If you tried "false", you would get "false is not truthy". If you tried "nil", you would get "nil is not truthy". If you put any string as "v", you would find that the string is truthy.

What is truthy and what is not? Anything that is not "nil" nor "false" is truthy. This is good to know because you can save time not typing "== nil" or "~= nil" or "== true" or "== false", because you know if the object is truthy. For example, you don't have to put ~= nil in the following:

if workspace:FindFirstChild("Base") ~= nil then
print("The base is there!")
else
print("All your base are belong to us")
end

Because :FindFirstChild() returns either an Instance or nil, we can deduce that only the desired outcome is truthy (Instances are truthy), and therefore we can omit "~= nil" as it is a pointless comparison.

if workspace:FindFirstChild("Base") then
print("The base is there!")
else
print("All your base are belong to us")
end

Keep this in mind when working with logical operators!
Report Abuse
TaslemGuy is not online. TaslemGuy
Joined: 10 Jun 2009
Total Posts: 12174
26 Sep 2012 07:16 PM
wait() yields two numbers: (1) time elapsed in wait, (2) current game time.

When you do:

while wait() do

It looks at (1) which is a number. Numbers are true-ish values (they're not false or nil) so it passes the check.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
26 Sep 2012 07:30 PM
Everything is true unless it's actually false or nil.

-------------------------
~thedestroyer115, nice and helpful posts- sometimes~
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
26 Sep 2012 07:35 PM
I think the fundamental misunderstanding here is that a function has to return a useful value, that has to get used for something.

There's generally two classes of function:

1) Functions that do some transformation on their inputs, and return a useful values.

A good example is something like math.sqrt. You'd have no reason to call it unless you wanted to use the return value.

2) Functions that have some side-effects based on their value, but do not return anything that is typically used.

Just like wait, print falls into category 2. While wait returns values, the user typically does not care about them, they only care about the "side effects" that the call had: In the case of wait, pausing the code for some time, and in the case of print, writing some output for the user to see.
Report Abuse
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
26 Sep 2012 07:53 PM
@thedestroyer; Or 0, am I right?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
27 Sep 2012 08:13 AM
Test it, and I believe 0 is false. But I might be totally wrong.

Report Abuse
cw2326 is not online. cw2326
Joined: 25 Aug 2011
Total Posts: 2459
27 Sep 2012 08:57 AM
while (wait(1)) do
print("This prints every second.")
end
Report Abuse
Mathfreak231 is not online. Mathfreak231
Joined: 21 Jun 2010
Total Posts: 5311
28 Sep 2012 05:12 PM
@thedestroyer

0 is true-y

FAIL COBRAS!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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