|
| 16 Jul 2014 04:14 PM |
I'm a bit unsure about booleans. I'm reading roblox wiki, and I think that booleans are true/false values, correct?
So, for example, is this script a boolean?
local forum = true if forum == true then print ("I got this right!") else print ("I need more practice.") end
Sorry for the trouble, this to you guys is probably child's play, but everyone has to start somewhere, right?
I come from LMaD, but I'm looking to retire to building and scripting. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:17 PM |
| A boolean is a variable that's either true or false. It's also a type of algebra, but you don't have to worry about that. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:17 PM |
That would work, yes. But you can also do this and still get the same outcome (it is optional):
local forum = true if forum then print("Yay") else print("No!") end
In other words, the conditional is translated to: if true then, as forum is just a variable for true. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:18 PM |
Can a boolean be a 1 or 2 value?
Like --
local forum = 1 if forum == 1 then print ("1") elseif print ("2") else print ("3") end |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:20 PM |
Ohhhh, so the '== true' is assumed, that makes sense. Would that be the same for '== false' or would you need to specify that it's equals false? |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:20 PM |
| No, it had to be either true or false. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:21 PM |
Okay, so this script below is just a conditional, not a boolean, correct?
--------------------- local forum = 1 if forum == 1 then print ("1") elseif print ("2") else print ("3") end --------------- |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:21 PM |
| Oh, and you have to specify if it has to be false. Yeah. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:22 PM |
| You have to have a condition for else is too. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:23 PM |
Thanks Coolio, I'm slowly learning. :D My goal is to know how to click on a brick, make it .5 transparency, then click it again to go back to 0 transparency. |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Jul 2014 04:24 PM |
What do you mean a condition for elseif?
|
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:25 PM |
if statement then
elseif statement2 then
elseif statement3 then
else
end |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:25 PM |
| For elseif, you have to do the same thing that you did with if. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:26 PM |
local forum = 1 if forum then print ("true") elseif forum == false then print ("false") else print ("neither") end
^ like that? |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:27 PM |
yes
also you can do
elseif not forum then
|
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:27 PM |
Oops, forgot to change local forum to true.
How about this?
local forum = true if forum then print ("true") elseif forum == false then print ("false") else print ("neither") end |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:27 PM |
| Yes, you're doing awesome! :) |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:28 PM |
I think I really understand booleans now. :D Time to move onto strings. ;) |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2014 04:43 PM |
Conditions in if-statements are booleans. You can look at if statements under-the-hood function that will only return true or false depending on the answer. If you can't make a true or false statement in the condition, then it's not a condition.
local s = 1
if s == 1 then -- true end
if s == 2 then -- false end |
|
|
| Report Abuse |
|
|