|
| 26 Sep 2012 03:43 PM |
| wait() isnt really anything that could be identified as true or false.. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 26 Sep 2012 05:25 PM |
| Wait (# of seconds) it's like waiting, The number of seconds! |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 26 Sep 2012 06:01 PM |
Yeah, I think the Wait() should be on top of the code.
Haters gonna hate |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
 |
| 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 |
|
|
|
| 26 Sep 2012 07:53 PM |
| @thedestroyer; Or 0, am I right? |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2012 08:13 AM |
Test it, and I believe 0 is false. But I might be totally wrong.
|
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 28 Sep 2012 05:12 PM |
@thedestroyer
0 is true-y
FAIL COBRAS! |
|
|
| Report Abuse |
|
|