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

Is return false / return true Different?

Asked by 3 years ago

I want to know is return false / return true different, And if it was different please tell me how its work

2 answers

Log in to vote
0
Answered by
Vathriel 510 Moderation Voter
3 years ago

It is different!

Remember that "false" and "true" are boolean values.

--Boolean overview
local myBool = true

if myBool == true then 
    print("my bool is true!")
else
    print("my bool is false!")
end

Experiment with that a little!

On to the "return" part.

Returning is a step in a function which: exits the function, and passes value(s) back to the caller.

So let's try it out with a less than 10 function!


function isLessThanTen(num) if num < 10 then return true else return false end end print(isLessThanTen(5)) print(isLessThanTen(100))
0
First print output: true, second one is false AntoninFearless 622 — 3y
0
Correct, which means we now have a function that can tell whether o not a number is less than 10! Think of it like a sentence: 5 Is less than ten? 100 Is less than 10? Vathriel 510 — 3y
1
return (num < 10) also works xD Ziffixture 6913 — 3y
0
Correct but that's not the point of what he asked. Vathriel 510 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

no its not really different it depends on the conditions its being returned to like

function food()
    return true
end
if food then
    --eats
end

--or

function food()
    return false
end
if not food then
    --does not eat
end
0
if not food then meaning false and if food then is basically saying if food is true Vetrodex 22 — 3y
0
or if food == 1 or if food == 0 (true or false) so its not really different its just based on how you use it in your conditions Vetrodex 22 — 3y

Answer this question