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

How do i make a boolean and what are they used for?

Asked by 9 years ago

How do i make a boolean and what are they used for?

2 answers

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
9 years ago

A boolean is a data type. Booleans have two values, either true or false.

To refer to a boolean, simply do:

local bool1 = true
local bool2 = false

print(bool1) --> true
print(bool2) --> false

There are numerous uses for booleans.

GuiObject Visibility:

local frame = Instance.new("Frame", somewhere)

frame.Visible = false --Sets the visibility to false or not visible
frame.Visible = true --Sets the visibility to true or visible
frame.Visible = not frame.Visible --Since Visible is a **boolean**, using the not before it makes the boolean the opposite of what it currently is

print(frame.Visible) --> false, since it was true then set to it's opposite, false

Conditional Statements:

if (condition) then action end

Yes the condition is in fact a boolean and whether it is true or false determines if the action is taken. If it is true the action will take place, if it is false then it will not.

Example:

--2 + 2 == 3 returns false so it will not print
if 2 + 2 == 3 then
print("2 plus 2 is actually three")
end

--2 + 2 == 4 returns true so it will print
if 2 + 2 == 4 then
print("2 plus 2 is actually four")
end

To learn more:

Roblox Wiki: Booleans

Ad
Log in to vote
1
Answered by 9 years ago

People would just say that there like true and false. They will return 1 of 2 things, it is either true or false. So

while hi do --they are used in things like this... so while hi = true it will do the loop
wait(1)
end

Answer this question